与Android和ks.getKieClasspathContainer()的Drools集成引发java.lang.NullPointerException

时间:2019-03-30 08:37:09

标签: java android drools

我一直在尝试使用Drools和Android Studio开发Sudoku游戏应用。但是我遇到了一个关于如何在Android应用程序中集成Drools的问题。我已经添加了jar文件。

implementation 'org.drools:drools-core:7.19.0.Final'
implementation files('libs/drools-android-7.19.0.Final.jar')
implementation files('libs/drools-compiler-7.19.0.Final.jar')

我创建了一个测试课程:

try {
            KieServices ks = KieServices.Factory.get();
            KieContainer kc = ks.getKieClasspathContainer();
            KieSession kSession = kc.newKieSession("SudokuKS");

            kSession.fireAllRules();
            kSession.dispose();
        } catch (Throwable t) {
            t.printStackTrace();
        } 

但是,当我运行该应用程序时,以下几行发生了一个问题:

KieContainer kc = ks.getKieClasspathContainer();

错误是:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.moxa.mysudoku, PID: 14267
    java.lang.NullPointerException: Attempt to invoke interface method 'org.kie.api.runtime.KieContainer org.kie.api.KieServices.getKieClasspathContainer()' on a null object reference
        at com.moxa.sudoku.RuleEngineTest.startEngine(RuleEngineTest.java:15)
        at com.moxa.sudoku.SudokuFunctions.check(SudokuFunctions.java:33)
        at com.moxa.sudoku.SudokuFunctions.getFunction(SudokuFunctions.java:21)
        at com.moxa.sudoku.view.functionsgrid.FunctionButton.onClick(FunctionButton.java:25)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

有人可以帮助我解决此问题吗?

0 个答案:

没有答案