• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to verify a jar has been loaded correctly

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic