`无法找到在Drools中class`错误(`Unable to find class` error

2019-09-18 03:54发布

我试图定义一个很简单的功能Drools如下:

import java.util.List;

function int sumLengths(List<String> strings) {
    int counter = 0;
    for (String s : strings)
        counter += s.length();
    return counter;
}

但它给我的错误:

Exception in thread "main" java.lang.RuntimeException: [ function sumLengths (line:5):
Unable to resolve type List<String> while building function. java.lang.ClassNotFoundException: Unable to find class 'List<String>' ]

任何想法?

Answer 1:

也许是与仿制药的问题( 这点我这样的结论)。 你有没有试过以下(或类似):

function int sumLengths(List strings) {
    int counter = 0;
    for (Object s : strings)
        counter += ((String) s).length();
    return counter;
}

如果它不工作,你可以用这个来代替:

function int sumLengths(String[] strings) {
    int counter = 0;
    int length = (strings != null) ? strings.length : -1;
    for (int idx = 0; idx < length; ++idx) {
        counter += strings[idx].length();
    }
    return counter;
}


Answer 2:

改成

function Boolean consulta(celda cref, java.util.List celdas) {

......

 celda c = (celda) celdas.get(y);
}


文章来源: `Unable to find class` error in Drools