• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to verify a jar has been loaded correctly  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application, I use classes that are contained in a jar file. One such class is called "jarStuff.ClassInJar"

I have a reference to a ClassInJar object that gets instantiated in the constructor of Class A when the program is started.

Basically:


Occasionally (1 out of 10 times), I get the following error:

Exception in Thread Main java.lang.NullPointerException
at test.A<init>Unknown Source

I'm not sure what the cause of the error is, but it is not consistent, and only occurs occasionally.
1. Is it possible that the error is getting thrown because the jar file has not yet been loaded before the constructor is called?
2. Is there a way to programatically verify a jar file has been loaded (and its classes are available) when a program starts?

Thank you.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is it possible that the error is getting thrown because the jar file has not yet been loaded before the constructor is called?


No. There is no such race condition. If the class is not found -- then it is not in the classpath... which of course, makes your second question moot.

BTW... can you show us the complete stack trace?

Henry
 
al langley
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Henry.
In the original code posting, I tried to simplify the problem (incorrectly thinking the problem was with loading the jar). But thanks to your answer, I see the problem may be in the code and classes inside the jar file. The stack trace was almost identical to the error message described in the original post, except the name of the class was different.

I'll post what I find (when i find it) for those who are interested so that they won't repeat my mistake.

Thanks for answering the question, I can at least look in the different place now for the problem.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!