This site requires JavaScript, please enable it in your browser!
Greenfoot back
drhorriblejr
drhorriblejr wrote ...

2022/7/14

Error reading file when game is exported

drhorriblejr drhorriblejr

2022/7/14

#
Hi all, I've been having some trouble reading text files in my game, the code I'm using works fine when run in the editor but when I export it I get this error: java.lang.RuntimeException - (JavaScript) ReferenceError: jl_NoClassDefFoundError And here is the code I use to load a file:
InputStream input = getClass().getResourceAsStream("levels/" + filename + ".txt");
Scanner reader = new Scanner(input);
Does anyone have experience reading from files after the switch to javascript/HTML5?
danpost danpost

2022/7/14

#
drhorriblejr wrote...
I've been having some trouble reading text files in my game, the code I'm using works fine when run in the editor but when I export it I get this error: java.lang.RuntimeException - (JavaScript) ReferenceError: jl_NoClassDefFoundError
What possible values may be assigned to filename?
drhorriblejr drhorriblejr

2022/7/14

#
That's just the name of the file without the extension. I currently only have one level named test so it makes the path "levels/test.txt," and that path exists in the greenfoot project directory locally
danpost danpost

2022/7/16

#
drhorriblejr wrote...
That's just the name of the file without the extension. I currently only have one level named test so it makes the path "levels/test.txt," and that path exists in the greenfoot project directory locally
Seems like you have everything in order. Maybe your file operations are not what javascript would allow.
You need to login to post a reply.