I'm taking some files from different folders in Java as below:
File d=new File(path); // Path here is surely not null
String s[]=d.list();
System.out.println("Directory: "+path+s[0]+"/");
Above code works in Eclipse and my OS is Ubuntu 14.04. When I compile and run the project from terminal, I get the following error:
Exception in thread "main" java.lang.NullPointerException
at io.ReadFile.read2Dir(ReadFile.java:97)
at io.ReadFile.readDir(ReadFile.java:134)
at gui.Run.readFile(Run.java:35)
at gui.Run.main(Run.java:304)
Even if s[0] corresponds to a folder, I get NullPointerException in terminal.
This is how I compile from terminal:
javac -sourcepath src -cp /home/myUsername/workspace/tezoz_my/ -encoding ISO-8859-1 src/gui/Run.java
By the way, I had to change encoding because project is created with ISO 8859-1.
Then I run the project:
java gui.Run
This is where the error occurs:
System.out.println("Directory: "+path+s[0]+"/");
Thanks.