Je rencontre des problèmes avec certains de mes codes et je n'arrive vraiment pas à résoudre cette erreur.Aide Java - StringIndexOutOfBoundsException - Index de chaîne hors de portée: -1
J'utilise Interprolog (Java + Prolog) voir here
Voici le stacktrace:
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)
et le code en question:
myEngine = new NativeEngine();
myEngine.consultFromPackage("C:\\interprolog212a\\userlist.p", LoginHandler.class);
boolean x = myEngine.deterministicGoal("hasAccess(user,pass)");
des idées? Je frappe un brickwall ...
oh et la ligne 24 est la deuxième ligne de code que j'ai posté.
modifier: le contenu de userlist.p:
hasAccess(tom,123).
hasAccess(bob,456).
suite à quelques-unes des suggestions ci-dessous, je me suis déplacé des classes loginhandler et liées à leur propre emballage et aussi userlist.p à l'ensemble, et maintenant i obtenir cette erreur:
com.declarativa.interprolog.util.IPException: Problem consulting from package archive:C:\Users\Keval\AppData\Local\Temp\IP_5283895338735856757\userlist.p
À quoi ressemble userList.pl? Ma seule supposition est que hasAccess (utilisateur, pass) ne joue pas bien avec ce qui est dans ce fichier. –
salut là, merci pour la réponse. J'ai modifié le post original et vous pouvez maintenant voir le contenu de userlist.pl. acclamations – KP65
Avez-vous accès au code source de NativeEngine pour voir ce qu'il essaie d'obtenir une sous-chaîne et comment il obtient l'index pour la sous-chaîne? – justkt