Java - listFiles()返回nullpointerexception

时间:2014-11-29 20:39:16

标签: java eclipse nullpointerexception

好吧,我正在运行从eclipse导出的Runnable JAR文件,我得到一个NullPointerException(在Linux VPS上)。在我的Windows PC中,它可以正常工作。这是我的代码:

public Main() throws Throwable {
    Policy.setPolicy(new PluginPolicy());
    System.setSecurityManager(new SecurityManager());

    File directory = new File("src/Plugins/Rogue/");

    File[] fList = directory.listFiles();
    if(fList.length > 0) { 
        for (File file : fList) {
            if (file.isFile()) {
                System.out.println(file.getName());
                String path = file.getParent().substring(4).replace("\\", ".");
                String pluginName = file.getName().split("\\.")[0];

                File unauthorizedJarFile = new File(pluginName + ".jar");
                ClassLoader unauthorizedLoader = URLClassLoader.newInstance(new URL[] { unauthorizedJarFile.toURI().toURL() });
                Plugin unauthorizedPlugin = (Plugin) unauthorizedLoader.loadClass(path + "." + pluginName).newInstance();
                unauthorizedPlugin.run();

            }
        }
    }
}

我在Linux VPS中得到了这个:

Exception in thread "main" java.lang.NullPointerException
        at Test.Main.<init>(Main.java:23)
        at Test.Main.main(Main.java:12)

以及我在Windows上的Eclipse IDE:

Rogue.java
swaggy!

任何帮助表示赞赏!感谢

0 个答案:

没有答案