File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ExceptionInInitializerError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ExceptionInInitializerError" Watch "ExceptionInInitializerError" New topic
Author

ExceptionInInitializerError

Jeremy Watts
Greenhorn

Joined: Jun 23, 2011
Posts: 18
Hi,

I have the following line in a class, that I have written:-

private MathContext mc = new MathContext(Configurations.SCALE, RoundingMode.HALF_UP);

Now, when I run the class, I get the error "ExceptionInInitializerError". I know that the error is produced by this line, as when I replace the static variable 'Configurations,SCALE', with say, the number 8, then I no longer recieve it.

How can i circumvent this error?

Thanks
Jeremy
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

If you look at the stack trace, you'll probably see something blowing up in the initialization of a static member variable in Configurations. If you wrote that class, you can fix that error in Configurations. If you didn't, and you can't modify it, then your only choice is not to use it.

ExceptinInInitializerError happens when a class if loaded (initialized, actually, but for most purposes we can consider them to be a single operation). If a class you're trying to use fails to load, you can't use that class, and any code that depends on that class can't execute. So you either fix the class, or find a replacement.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Expanding on that a bit: the stack trace should have a stack trace for the ExceptionInInitializerError, followed by "caused by", followed by another exception stack trace that shows more detail about what happened. Possibly followed by another "caused by", and possibly more. Focus on the last "caused by" stack trace, as that's the root cause of your problems. If you don't see any "caused by", then you need to focus on how your errors are being logged, because you are losing valuable information. If you don't have a proper logging framework at least use e.printStackTrace() rather than System.out.println(e).
Jeremy Watts
Greenhorn

Joined: Jun 23, 2011
Posts: 18
Thanks for your help, both of you. I did as you said, but sadly couldnt make much sense out of any of it. But, I re-jigged the class, by taking the SCALE variable out of the Configurations class, and adding it to the other class, that uses the MathContext line, as a static instance variable. This has seemed to work fine.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It would be good to learn how to diagnose these problems. It's not that hard, and it's a pretty fundamental and important skill. If you paste in your full stack trace, somebody here will be able to help you make sense of it. You won't get very far in Java programming if you don't learn to read a stack trace.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ExceptionInInitializerError