This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I think my problem is simple - I have a program that I compiled. When I run it, I get a NullPointerException. However when I run it from my IDE (interpreted instead of compiled), it runs fine. Any reason for this? (Probably have a bad classpath.)
In all likelihood it has nothing to do with compilation (and I'm fairly certain that the IDE also compiles the code). Any number of settings could be different within an IDE than they are outside of it.
Post the full stack trace, the code that causes the exception to be thrown, and tell us which object is null (assuming that it happens in your code).
Rob Prime wrote:Unless you're using JDK 7, I doubt it. There is no class called ResourceMap in Java 6.
Huh, I am using JDK 6, yet the ResourceMap code worked perfectly when I ran it from the IDE. I should also note that this was code generated by the IDE when using the automatic GUI builder. (I'm using NetBeans 6.5.1)
Anyway, I see two potential causes:
Either chartPanel or resourceMap is null. The line number of the code that is throwing the exception is line 95 - can you tell us what line 95 is?
It's from JDesktop; I found out by searching for a combination of FrameView and ResourceMap.
Michael Keller wrote:Yes, it's
I find that highly questionable. The NullPointerException ends in your FileIOTestView constructor, meaning it is that constructor that throws the exception, not a method called by the constructor. That means that there is a null reference in the constructor itself that is being dereferenced. Are you sure that's not line 94 instead of line 95? That would make resourceMap null.
I found the API forFrameView, and found its getResourceMap method. However, there was nothing in the API that said that getResourceMap() could return null.
Can you print out the value of resourceMap right after you initialize it?
Joined: Jul 06, 2009
I will try that. In the meantime, I do know that I do not get any errors when I compile and run it from the IDE, just when I use the command line.
Edit: You were right! It wasn't in that line at all, but the next line:
My mistake, I misread the line number. Or just forgot it.
Joined: Mar 22, 2005
In that case I'd guess that the value is coming from a properties file that is present where the IDE can find it, but which is not on the classpath outside of it. Or something like that.
Joined: Jul 06, 2009
I think I will rewrite this to not use the ResourceMap, thus bypassing this problem entirely. Thank you for helping me pinpoint it, though.
Joined: Feb 26, 2008
I initially thought what Ulf wrote (you can see i edited my previous post)
In that case I'd guess that the value is coming from a properties file that is present where the IDE can find it, but which is not on the classpath outside of it.
However, if the properties file is not found, wouldn't it give a ResourceNotFound exception?
May be, the code is able to find the properties file, and reading some value from it and trying to create a ResourceMap object. But it is not finding the required value and hence object is not getting created.