Nullpointer exception... any help would be appreciated

In advance, I apologize for any ignorance which I may obviously have... I'm in the process of learning Java, and am used to C/C++... In any case, I'm running into a nullpointer exception while 'compiling', which I'm having trouble figuring out... I'll list everything below, but this message will be rather long, as I will try to include everything I can. For this reason, I will ask my questions here, at the top:
1) A null pointer exception, I believe, is generated when something is being referenced which is currently null, for example "a=null; a.b;" yields a null pointer exception. However, is there any other way that one is generated?
2) Are there methods to figure out what/why something is null other than simply looking at it? As shown below, it seems that just looking at it runs you in a circle from line to line, file to file, which leads you back to the beginning where nothing is actually null... (I'm probably just not seeing it, but that seems to be what's happening to me)
So now, on to the actual code:
The following is a printout of the debugging info:
~/bin/jdk*/bin/java -classpath classes jamie.Main
java.lang.NullPointerException
at jamie.Main.Sys_Log(Main.java:110)
at jamie.Main.Setup(Main.java:142)
at jamie.Main.main(Main.java:54)
Exception in thread "main" java.lang.NullPointerException
at jamie.Main.Sys_Log(Main.java:110)
at jamie.Main.Shutdown(Main.java:182)
at jamie.Main.main(Main.java:92)And a short excerpt of each. (*) indicates line which error originates:
20    )   private static Log                sys_log;
108  )   static void Sys_Log(String msg)
109  )   {
110*)        sys_log.Log(msg);
111  )   }
142*)   Sys_Log("Server warming up...");
182*)   Sys_Log("Server shutting down...");
50  )     public static void main(String[] args)
51  )     {
52  )          try
53  )          {
54*)                Setup();
85  )     catch(Exception e)
86  )     {
87  )          e.printStackTrace(System.out);
88  )          err_log.Log(e.toString());
89  )     }
90  )     finally
91  )     {
92*)            Shutdown();
93  )      }Now, various things that I have tried, and their result (you can probably skip this section, as these were mostly futile efforts):
What seems odd to me is that the initial error is on line 110, which is the logging function Sys_Log. Since it's a null pointer exception, I would assume that sys_log is null? and thus in calling Log we're generating that error... I'm not entirely sure that that makes sense, though. Additionally, and what I find odd, is that if I change it to what I will list below, I get a slew of other seemingly unrelated problems:
20    )   private static Log                sys_log;
108  )   static void Sys_Log(String msg)
109  )   {
110#)        if (sys_log!=null)
111  )        sys_log.Log(msg);
112  )   }This results in a problem with function Err_Log, which I change the same way, resulting in the following:
java.lang.NullPointerException
        at jamie.Area_LUL.Load(Area_LUL.java:23)
        at jamie.Main.Setup(Main.java:161)
        at jamie.Main.main(Main.java:55)
Exception in thread "main" java.lang.NullPointerException
        at jamie.Main.Shutdown(Main.java:186)
        at jamie.Main.main(Main.java:93)In Main.java the following lines are generating the error:
160  )   lul = new Area_LUL();
161*)   lul.Load();And in Area_LUL.java I also have the following:
14  )class Area_LUL implements LoaderUnloader
15  ){
16  )    public void Load()
17  )    {
18  )        try
19  )        {
20  )            areadir = new File("./areas/");
21  )            SAXParser p = SAXParserFactory.newInstance().newSAXParser();
22  )
23*)            for(File curr : areadir.listFiles(new Area_Filter()))
24  )            {
25  )                p.parse(curr, new XMLParser());
26  )            }
27  )        }Where in the above, the for statement is generating the null pointer exception... which would tell me that areadir is null, however it is defined as new File("./areas/"); Also, lul (defined as new Area_LUL(); is generating the same error, though it is clearly defined in Area_LUL.java at the top of the last excerpt.
Also, LoaderUnloader is defined in another file as follows:
interface LoaderUnloader
    void Load();
    void Unload();
}which are defined in Area_LUL in Area_LUL.java .
A major theory which I currently have is that the compiler is beginning with my main.java file, and not seeing the class definition in another file, and thus attributing the class obj I create as null, which is causing the error, but I also am not sure if this is possible...
My imports for Main.java are as follows:
package jamie;
import java.io.*;
import java.util.*;I'm not entirely sure what the package is including, however I do have a jamie.jar file in another directory (../../dist) (could be referencing that?). Also, to compile the source I am using the following command:
~/bin/jdk*/bin/java -classpath classes jamie.MainHowever my classpath (I believe) isn't set to include all my files in the given directory. I wouldn't believe that this would be an issue, however if it could possibly be causing this, I can figure out how to set it properly. Also, this should mean I'm starting with Main.java, and perhaps I am right in concluding that it isn't referencing Area_LUL in another file properly, which is setting it as null?
In any case... Any help would be greatly appreciated. This has been a bit of a struggle for about a month now, trying various resources, moving things around, etc... Thanks so much for your time in reading,
-Jess

I'm not able to follow the program flow from your post. Please create a small standalone program that exhibits the problem and post that back here.
Your assumption re a NPE is correct, that's the only way they're generated.
There are no "canned" methods to resolve NPEs. The best solution is to put System.out.println statements for all of the involved objects and variables immediately preceeding the error line (in this case, 110) and something will show null. Usually that's enough info to backtrace to the real cause.

Similar Messages

Maybe you are looking for