File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NullPointerException when compiled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException when compiled" Watch "NullPointerException when compiled" New topic
Author

NullPointerException when compiled

Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
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.)
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
For bad classpath it should throw class not found exception. Can you post your programme and stack trace.


SCJP 1.5(97%) My Blog
vvv gupta
Greenhorn

Joined: Jun 03, 2008
Posts: 4
This could happen like If you did some code changes in previous fine complied code and you compiling new code getting error in new code.

Where it might be possible you are running without compilation only the previous version of code ithat is previous class file only.

either to refresh your IDE.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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).


Ping & DNS - updated with new look and Ping home screen widget
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
Here is the stack trace:



And here is the relevant part of the program (Where the stacktrace says the error is):

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Does the call to getResourceMap() return a valid (i.e., non-null) object, and does it include a value for "StatusBar.messageTimeout"?
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
It should - at least it does when I run it from the IDE, but not from the compiled code.
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
Can you post the code for

method?

Jhakda

If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
Jhakda Velu wrote:Can you post the code for

method?

Jhakda


Probably, if I can find it. It's not my method, though. I thought it came with the latest JDK.

I'll edit this post with the code when I find it.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Michael Keller wrote:Probably, if I can find it. It's not my method, though. I thought it came with the latest JDK.

Unless you're using JDK 7, I doubt it. There is no class called ResourceMap in Java 6.

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
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?


Yes, it's
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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?
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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.
Michael Keller
Greenhorn

Joined: Jul 06, 2009
Posts: 10
I think I will rewrite this to not use the ResourceMap, thus bypassing this problem entirely. Thank you for helping me pinpoint it, though.
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
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.

Jhakda
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

vvv gupta wrote:

Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException when compiled
 
Similar Threads
NullPointerException (UnknownSource)
Unable to compile class for JSP
NullPointerException error
Problem with using selectionSort on number input, says cannot be applied to int
Help with In-Q -My and struts