I have a folder with Tomcat7 installed on my disk that I use to do some tests on my web application running it from eclipse and it I works well. When I try to deploy the application on a stand alone tomcat server it gives an error: (I’m using windows)
Fev 08, 2012 9:10:04 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Process
java.lang.NullPointerException
at hs.server.CommandFactory.<init>(CommandFactory.java:27)
at hs.server.Process.init(Process.java:40)
and the line 27 is in this context:
19-String pathname = "/"+packageName.replace(".", "/")+"/";
20 //String pathname = packageName.replace(".", "/");
21- URL resource = loader.getResource(pathname);
22- File commandDir = (new File(resource.getFile()));
23-
24- //File commandDir = new File(loader.getResource(packageName.replace(".", 25-"/")).getFile());
26-
27- for(String classFilepath: commandDir.list()) {
I guess is something about the URL but the problem is that I’m running it without any problems on the tomcat instance on eclipse. Thank you
File.list()will returnnullifFilerepresents a non-existent directory. Thisnullwill then cause yourforloop to throw a null-pointer exception.You need to make your code defensive, and check that the directory exists using the methods on
Filebefore you attempt to read it.