0

我的一些代码有问题,我真的无法解决这个错误。

我正在使用 Interprolog(Java+Prolog) 看这里

这是堆栈跟踪:

  Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(Unknown Source)
    at      com.declarativa.interprolog.AbstractPrologEngine.copyToTemp(AbstractPrologEngine.java)
 at com.declarativa.interprolog.AbstractPrologEngine.consultFromPackage(AbstractPrologEngine.java)
 at LoginHandler.actionPerformed(LoginHandler.java:24)
 at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
 at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
 at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
 at java.awt.Component.processMouseEvent(Unknown Source)
 at javax.swing.JComponent.processMouseEvent(Unknown Source)
 at java.awt.Component.processEvent(Unknown Source)
 at java.awt.Container.processEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)

和有问题的代码:

      myEngine = new NativeEngine();
  myEngine.consultFromPackage("C:\\interprolog212a\\userlist.p", LoginHandler.class);
  boolean x = myEngine.deterministicGoal("hasAccess(user,pass)");

有任何想法吗?我撞墙了...

哦,第 24 行是我发布的第二行代码。

编辑:userlist.p 的内容:

hasAccess(tom,123).
hasAccess(bob,456).

根据下面的一些建议,我将 loginhandler 和相关类移到了他们自己的包中,并将 userlist.p 移到了包中,现在我收到了这个错误:

com.declarativa.interprolog.util.IPException: Problem consulting from package         archive:C:\Users\Keval\AppData\Local\Temp\IP_5283895338735856757\userlist.p
4

2 回答 2

2

我想是开源的。它正在这样做:

String className = rc.getName();    
String packageName = className.substring(0,className.lastIndexOf('.'));

rc是你的呼叫班。所以我想你的LoginHandler课程在默认包中,这会让这段代码出错?尝试将它放入一个包中,即添加package blah;到它的顶部并将其移动到具有该名称的目录中。

它这样做是因为它假设它userlist.pl实际上与您的代码位于同一位置,并且它试图使用包名称来查找您的代码加载的位置。我不认为您可以使用consultFromPackage()实际尝试的方式,因为据说它只能解析文件名,而不是完整的路径。

哦,你可以得到源。它在从网站链接的zip 文件中。

于 2010-02-12T15:35:57.097 回答
0

\\路径中的第二个是否令人困惑?如果它正在做任何事情来检查路径中的每个目录,它可能会被一个空字符串混淆,也许?

于 2010-02-12T15:23:46.933 回答