Gremlin92
@Gremlin92
Целеустремленный

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();
              }
            }
        }  
    }
}

В строчке с File
5f4cab0721e80147677545.png
  • Вопрос задан
  • 105 просмотров
Решения вопроса 2
zagayevskiy
@zagayevskiy Куратор тега Java
Android developer at Yandex
Читаем доку к System.getProperty...
@return the string value of the system property, or null if there is no property with that key.

очевидно, оно вернуло null
Читаем доку к конструктору файла
@throws NullPointerException If the pathname argument is null

Вот тебе, бабушка, и NPE.
Ответ написан
Gremlin92
@Gremlin92 Автор вопроса
Целеустремленный
Поменял на это
listpaths = new ArrayList<String>();
        String currentWorkingDir = /*System.getProperty(*/"Z:\\Радио"/*)*/;
        File file = new File(currentWorkingDir);
        showFilesAndDirectoryes(file);
        listpaths.clear();
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы