E
E
Evgeny Petryaev2020-08-31 10:44:23
Java
Evgeny Petryaev, 2020-08-31 10:44:23

Null pointer exception?

package example;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Example {
    static List<String> listpaths;
    public static void main(String[] args) throws Exception {
        
        //GeneratePlaylist g = new GeneratePlaylist();
        //g.LoadFromFiles();
        listpaths = new ArrayList<String>();
        String currentWorkingDir = System.getProperty("Z:\\Радио");
        File file = new File(currentWorkingDir);
        showFilesAndDirectoryes(file);
        listpaths.clear();
    }
    
    public static void showFilesAndDirectoryes (File f) throws Exception  {
        
        File[] files = f.listFiles();
        for(File p:files){
            if (!p.isDirectory ()) {
                System.out.println (p.getName ());
                listpaths.add(p.getName());
                System.out.println (p.getAbsolutePath());
            }
            if (p.isDirectory ()) { 
            try {
                showFilesAndDirectoryes (p); 
            }
            catch(Exception e){
                 e.printStackTrace();
              }
            }
        }  
    }
}

In line with File
5f4cab0721e80147677545.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-08-31
@Gremlin92

Reading the doc to System.getProperty...

@return the string value of the system property, or nullif there is no property with that key.

obviously it returned null
We read the doc to the file constructor
@throws NullPointerException If the pathnameargument isnull

Here's to you, grandmother, and NPE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question