`Unable to find class` error in Drools

微笑、不失礼 提交于 2019-12-10 21:34:23

问题


I'm trying to define a very simple function in Drools as below:

import java.util.List;

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

but it gives me error:

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>' ]

any idea?


回答1:


Perhaps it is an issue with generics (This points me to that conclusion). Have you tried the following (or similar):

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

If it doesn't work you could use this instead:

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;
}



回答2:


change to

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

......

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


来源:https://stackoverflow.com/questions/11062657/unable-to-find-class-error-in-drools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!