我正在尝试运行一个使用 drool.net 的简单应用程序。每当我执行时,应用程序在builder.AddPackageFromDrl("DroolsApp.Rules.drl", stream);
错误处崩溃,指出 NullReferenceException 未处理并且对象引用未设置对象的实例。我试图更改 drl 文件,但错误仍然存在。我错过了什么吗?还有没有任何网站提供使用 drools.net 的详细教程,我是否需要任何特定的程序来创建和编辑 drl 文件,因为我使用的是一个简单的记事本。
提前致谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.drools.dotnet.compiler;
using org.drools.dotnet.rule;
using org.drools.dotnet;
using System.IO;
using System.Reflection;
namespace DroolsApp
{
class Program
{
static void Main(string[] args)
{
PackageBuilder builder = new PackageBuilder();
Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("DroolsApp.Rules.drl");
builder.AddPackageFromDrl("DroolsApp.Rules.drl", stream);
Package pkg = builder.GetPackage();
RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
ruleBase.AddPackage(pkg);
executeRules(ruleBase, 5);
executeRules(ruleBase, 6);
executeRules(ruleBase, 7);
}
public static void executeRules(RuleBase ruleBase, int amount)
{
WorkingMemory workingMemory = ruleBase.NewWorkingMemory();
Quest quest = new Quest();
quest.Value = amount;
workingMemory.assertObject(quest);
workingMemory.fireAllRules();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DroolsApp
{
class Quest
{
public int Value { set; get; }
}
}
DRL File:
package DroolsApp
rule "NumberFive"
when
quest : Quest( Value == 5 )
then
Console.WriteLine("FIVE");
end
rule "NumberSix"
when
quest : Quest( Value == 6 )
then
Console.WriteLine("SIX");
end
堆栈跟踪:
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=drools.dotnet
StackTrace:
at org.drools.dotnet.semantics.DotnetClassTypeResolver.resolveType(String className)
at org.drools.semantics.java.RuleBuilder.build(ColumnDescr columnDescr)
at org.drools.semantics.java.RuleBuilder.build(RuleDescr ruleDescr)
at org.drools.semantics.java.RuleBuilder.build(Package pkg, RuleDescr ruleDescr)
at org.drools.compiler.PackageBuilder.addRule(RuleDescr ruleDescr)
at org.drools.compiler.PackageBuilder.addPackage(PackageDescr packageDescr)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(String fileName, Reader reader)
at org.drools.dotnet.compiler.PackageBuilder.AddPackageFromDrl(String fileName, Stream drlStream)
at MinimalDroolsForm.Program.Main(String[] args) in C:\Users\Carl\Desktop\DroolsApp\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: