Drools Android集成项目错误

时间:2017-04-13 10:47:52

标签: android android-activity drools

public KnowledgeBase loadKnowledge(final Context context, String propspath, String knowlegpath, ResourceType type){    

    InputStream is= null;
    try {
        is = new FileInputStream(propspath);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    String pakage = context.getPackageName();
        Properties props = new Properties();
    props.put("drools.dialect.java.compiler", "JANINO");
    PackageBuilderConfiguration cfg = new PackageBuilderConfiguration( props);
    JavaDialectConfiguration javaConf =  new JavaDialectConfiguration( );
    javaConf.init(cfg);
    cfg.setDialectConfiguration( "java", javaConf );
    PackageBuilder builder = new PackageBuilder( cfg );
    try {
        builder.addPackageFromDrl(new InputStreamReader(is));
    } catch (DroolsParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    RuleBase ruleBase  = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( builder.getPackage() );
        try {
            props.load(getAssets().open(propspath));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        for (String fname : context.getFilesDir().list()) {
            if (fname.endsWith("dex") || fname.endsWith("apk")) {
                context.deleteFile(fname);
            }
        }



       /* KnowledgeBuilderConfiguration kbuilderConf =
                KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props, Dialect.class.getClassLoader());*/
    KnowledgeBuilderConfiguration kbuilderConf =
            KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props);
        final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConf);


        ((KnowledgeBuilderImpl) kbuilder).setPackage(pakage);

    try {
       /* Resource res = ResourceFactory.newClassPathResource(knowlegpath);*/
        Resource res = ResourceFactory.newFileResource(knowlegpath);
        kbuilder.add(res, type);
        KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
        kBase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
    } catch (Exception ex) {
        ex.printStackTrace();
    }
        if (kbuilder.hasErrors()) {
            if (context instanceof Activity) {
                ((Activity) context).runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(context,
                                kbuilder.getErrors().toString(), Toast.LENGTH_SHORT).show();
                    }
                });
            } else {
                System.err.println(kbuilder.getErrors().toString());
            }

            return null;
        }
        KnowledgeBaseConfiguration kbaseConf =
                KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, ClassLoader.getSystemClassLoader());
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConf);
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        return kbase;


}

我在这里遇到的错误是 link to solve this error but not able to find jar files

failed to remove uid from uid_cputime module
    java.io.FileNotFoundException: /proc/uid_cputime/remove_uid_range (No such file or directory)
 at java.io.FileOutputStream.open(Native Method)
  at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
  at java.io.FileOutputStream.<init>(FileOutputStream.java:108)
  at java.io.FileWriter.<init>(FileWriter.java:63)
  at com.android.internal.os.KernelUidCpuTimeReader.removeUid(KernelUidCpuTimeReader.java:158)
  at com.android.internal.os.BatteryStatsImpl.removeUidStatsLocked(BatteryStatsImpl.java:9805)
  at com.android.server.am.BatteryStatsService.removeUid(BatteryStatsService.java:291)
  at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:17805)
  at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18294)
  at com.android.server.pm.PackageManagerService$8.run(PackageManagerService.java:11407)
  at android.os.Handler.handleCallback(Handler.java:751)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:154)
  at android.os.HandlerThread.run(HandlerThread.java:61)

0 个答案:

没有答案