Reputation: 49329
While working on my previous problem,
Java Jar Class Not Found Exception
I noticed something odd. the class that can not be found is referenced from main. Now if i try to create an instance of the class like
SysTray tray = new SysTray();
i get a class not found exception when i try to run the application but if i create it like
static SysTray tray = new SysTray();
it gets loaded no problems are reported.
I was wondering if anyone know why is this?
This should have nothing to do with class path because there are no external depencies and application is contained in a jar.
Upvotes: 0
Views: 226
Reputation: 12243
Do you actually access the static field ? I don't remember but i think the jvm is free to run the static initialization lazy (on first class reference or something.
Upvotes: 0
Reputation: 346310
Can you show us the actual code or, if it's too large try to reproduce the error in a smaller example?
The only thing that could explain this would be the static reference being outside the main class and thus not actually loaded until the class it's defined in is first accessed.
Upvotes: 3