very real and accessible text file "is missing or inaccessible"
              in 
             Programming Questions 
              •  
              3 months ago    
            
 
           
             I am working on a game that retrieves information from text files to construct a variety of in game objects. The architecture of my data folder looks like this:
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
             
            
            
             
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
 
            
           
             data
            
            
             data/ships
            
            
             data/ships/Interceptor.txt
            
            
             data/sprites 
            
            
             data/sprites/modules
            
            
             data/sprites/weapons
            
            
             data/sprites/weapons/Laser.png
            
            
             data/sprites/projectiles
            
            
             data/sprites/projectiles/Laser.png
            
            
             data/sprites/ships
            
            
             data/sprites/ships/Interceptor.png
            
            
             data/weapons
            
            
             data/weapons/Laser.txt
            
            
             the first class to try and call a file is this:
            
            - class Ship extends Object{
 - PVector v;
 - Ship target;
 - String[] input;
 - Boolean snapcam, piloted;
 - float velocity, translation, acceleration, rotationspeed, shield, shieldregenrate;
 - ArrayList weapons;
 - Ship(String file){
 - angle = 0;
 - velocity = 0;
 - translation = 0;
 - weapons = new ArrayList();
 - input = loadStrings("ships/" + file + ".txt"); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*ERROR*
 - sprite = loadImage("sprites/" + input[0] + ".png");
 - speed = float(input[1]);
 - acceleration = float(input[2]);
 - rotationspeed = float(input[3]);
 - shield = float(input[4]);
 - shieldregenrate = float(input[5]);
 - for (int i = 7; i <= 7 + int(input[6])*3; i+=3){
 - weapons.add(new Weapon(input[i], float(input[i+1]), float(input[i+2]) ) );
 - }
 - }
 
             when called, the following error occurs and stops the sketch:
            
            
              The file "ships/Interceptor.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
             
             
              Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
             
             
               at processing.core.PApplet.runSketch(PApplet.java:9660)
             
             
               at processing.core.PApplet.main(PApplet.java:9469)
             
             
              Caused by: java.lang.NullPointerException
             
             
               at Laser_Ships_2_0$Ship.<init>(Laser_Ships_2_0.java:184)
             
             
               at Laser_Ships_2_0.loadtest(Laser_Ships_2_0.java:312)
             
             
               at Laser_Ships_2_0$_Game.<init>(Laser_Ships_2_0.java:52)
             
             
               at Laser_Ships_2_0.<init>(Laser_Ships_2_0.java:87)
             
             
               at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
             
             
               at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
             
             
               at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
             
             
               at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
             
             
               at java.lang.Class.newInstance0(Class.java:355)
             
             
               at java.lang.Class.newInstance(Class.java:308)
             
             
               at processing.core.PApplet.runSketch(PApplet.java:9658)
             
             
               ... 1 more
             
            
             Trouble shooting steps I've taken so far,
            
            
             *Made sure all files existed and had correct names and extensions.
            
            
             *Ran test sketches to confirm I know how to use loadStrings() and that it's working.
            
            
             *Made sure there are no properties of the file making it inaccessible to the sketch.
            
            
             *Changed the encoding of the .txt file to UTF-8
            
            
             *Restarted processing, restarted computer.
            
            
             Note, I have extremely limited internet access.
            
            
             Thank you for your help! :)
            
            
             **additional note, when all file references are commented out of the code a null pointer exception occurs without any information on where it occurred. That did not happen previous to the files or file reading code being added.
            
 
            
              
              1  
            
 
            
 
            
             