tags:

views:

148

answers:

2

While working on my previous problem,

http://stackoverflow.com/questions/950636/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.

+3  A: 

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.

Michael Borgwardt
A: 

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.

Toader Mihai Claudiu