SaveGame.saveGame() isn't working anymore for me

It worked before, I don’t know what’s going on. My jmp is up to date. I do:



[java]

SaveGame.saveGame(“kinetrax/musics”, “Musics”, track.getAudioNode().getParent().getParent().getParent());

[/java]



And it throws this exception :



[java]

java.lang.StringIndexOutOfBoundsException: String index out of range: 1

at java.lang.String.charAt(String.java:695)

at java.util.regex.Matcher.appendReplacement(Matcher.java:761)

at java.util.regex.Matcher.replaceAll(Matcher.java:905)

at java.lang.String.replaceAll(String.java:2210)

at jme3tools.savegame.SaveGame.saveGame(SaveGame.java:41)

at kinetrax.nifty.control.screen.soundeditor.SoundEditorScreenControl.save(SoundEditorScreenControl.java:135)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:601)

at de.lessvoid.nifty.NiftyMethodInvoker.callMethod(NiftyMethodInvoker.java:145)

at de.lessvoid.nifty.NiftyMethodInvoker.performInvoke(NiftyMethodInvoker.java:104)

at de.lessvoid.nifty.Nifty$DelayedMethodInvoke.perform(Nifty.java:1176)

at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1154)

at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:312)

at de.lessvoid.nifty.Nifty.access$1500(Nifty.java:73)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1371)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)

at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:121)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:313)

at de.lessvoid.nifty.Nifty.update(Nifty.java:248)

at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:90)

at com.jme3.input.InputManager.processQueue(InputManager.java:1485)

at com.jme3.input.InputManager.update(InputManager.java:1702)

at com.jme3.app.Application.update(Application.java:595)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:178)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:225)

at java.lang.Thread.run(Thread.java:722)

[/java]

you sure your node name doesn’t contain any special characters? also try using a slash before the path maybe if that doesn’t work.

I think this line will fail on Windows:

File daveFolder = new File(JmeSystem.getStorageFolder().getAbsolutePath() + File.separator + gamePath.replaceAll("/", File.separator));



Maybe try replace() instead of replaceAll().



At least my memory says that replaceAll() accepts escapes in the second parameter and so the File.separator on Windows would need to be double-escaped.

Specifically:

gamePath.replace( ‘/’, File.separatorChar )



…which would also avoid the internal regex creation. Though that’s not really a performance issue in this case… it is unnecessary.



I assume this path must be used to compare to actual system paths or something? Otherwise, this replacement isn’t even needed. Java file IO should properly use “/” as a file separator on any platform. It’s only when you need to do comparison with retrieved File paths that it matters.

Thanks, problem solved. And yes, it didn’t contain any special characters, and the solution was doing :



[java]

SaveGame.saveGame(“kinetrax”, “Musics”, track.getAudioNode().getParent().getParent().getParent());

[/java]



instead of :



[java]

SaveGame.saveGame(“kinetrax/musics”, “Musics”, track.getAudioNode().getParent().getParent().getParent());

[/java]



Btw, it worked before…



Ah, and putting a slash like this [patch]/kinectrax[/patch] doesn’t work too.



@pspeed: hmmm, yeah, I’m running it on windows.

Looks like the “java.lang.StringIndexOutOfBoundsException: String index out of range: 1” is a known bug in java



See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6523151



Thread: http://stackoverflow.com/questions/1049103/why-am-i-getting-a-stringindexoutofboundsexception-when-i-try-to-replace-wi



Btw. is it ok that…



[java] public static BinaryImporter getInstance() {

return new BinaryImporter();

}[/java]



… always returns a new instance?

That’s not a bug. You have to double escape the in the replacement string because of the possibility of substitution.



But really, if you are just replacing one character with another then there is 0 reason to use replaceAll() when a much cheaper replace() does exactly what you’d want.

@pspeed The replaceAll is used in the SaveGame class



Check TestSaveGame for usage.



Escaping doesn’t work in this case.



Btw. is it ok that…



[java] public static BinaryImporter getInstance() {

return new BinaryImporter();

}[/java]



… always returns a new instance?

@douter said:
@pspeed The replaceAll is used in the SaveGame class

Check TestSaveGame for usage.

Escaping doesn't work in this case.


Yes, SaveGame is busted. But Java isn't.

SaveGame starts up the Mac truck, loads it up with 500 tons of carrots, and then drives down to the foot of the driveway just to get a piece of mail from the mailbox.

(In this metaphor, the part of the Mac truck was played by the Java regex infrastructure and the part of the trip down the driveway is played by the really simple and fast 0-overhead replace() call.) :)


!=



:wink:



As paul said, we just need to use replace() here.

You have my type “mac” so many times that my fingers don’t know how to type “mack” anymore. :slight_smile: (But now I have the Convoy song running through my head again… ;))

… I just replaced the image with the “real” Mack from Rubber Duck ^^

@normen said:
.. I just replaced the image with the "real" Mack from Rubber Duck ^^


I wondered what had happened.

...and now we've just about buried this thread. :)

Anything interesting going on here else? xD

What about the BinaryImporter?

Yeah, you always need a new instance to import on one thread.