Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException when compiled

 
Michael Keller
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For bad classpath it should throw class not found exception. Can you post your programme and stack trace.
 
vvv gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Michael Keller
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the stack trace:



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

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should - at least it does when I run it from the IDE, but not from the compiled code.
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code for

method?

Jhakda
 
Michael Keller
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Michael Keller
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vvv gupta wrote:

Please check your private messages for an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic