Hey,
I'm attempting to load two text files and, although I've solved this problem a few times before, nothing I try seems to work. If anyone can think of something to try it'll help! ^.^ Here is what the section of code that is causing the errors currently looks like:
//Load Text File Array public String[] loadTextFileArray(final String a) { String[] c = null; int i = 0; try { URL url = this.getClass().getClassLoader().getResource(a); final BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(url.toURI()))); while(bufferedReader.readLine() != null) { c[i] = bufferedReader.readLine(); i++; } bufferedReader.close(); return c; } catch(Exception e) { e.printStackTrace(); } return null; }
Here is the code using the above method:
String[] npcValues = resource.loadTextFileArray("Resources/Maps/Sprites/"+mapId+"_Sprites.txt"); String[] waypointValues = resource.loadTextFileArray("Resources/Maps/Sprites/"+mapId+"_Waypoints.txt");
...and here is the error message. No matter what I've tried I either get a FileNotFoundException or it'll give a null pointer exception.
java.lang.NullPointerException at Core.ResourceHandler.loadTextFileArray(ResourceHandler.java:121) at Entity.NPC.loadNpc(NPC.java:22) at Screens.ScreenGame.logicUpdate(ScreenGame.java:45) at Screens.ScreenGame.render(ScreenGame.java:102) at Core.GameCanvas.render(GameCanvas.java:111) at Core.GameCanvas.run(GameCanvas.java:73) at java.lang.Thread.run(Thread.java:722) java.lang.NullPointerException at Core.ResourceHandler.loadTextFileArray(ResourceHandler.java:121) at Entity.NPC.loadNpc(NPC.java:23) at Screens.ScreenGame.logicUpdate(ScreenGame.java:45) at Screens.ScreenGame.render(ScreenGame.java:102) at Core.GameCanvas.render(GameCanvas.java:111) at Core.GameCanvas.run(GameCanvas.java:73) at java.lang.Thread.run(Thread.java:722) Exception in thread "Thread-3" java.lang.NullPointerException at Entity.NPC.loadNpc(NPC.java:24) at Screens.ScreenGame.logicUpdate(ScreenGame.java:45) at Screens.ScreenGame.render(ScreenGame.java:102) at Core.GameCanvas.render(GameCanvas.java:111) at Core.GameCanvas.run(GameCanvas.java:73) at java.lang.Thread.run(Thread.java:722)
Edit: I just went looking around the forum for the first time in a while and noticed that there is a specific section for this, sorry for posting in the wrong area. >.<