java.lang.ExceptionInInitializerError Caused by: java.lang.ArithmeticException

Posted: May 9, 2012 in Java

ExceptionInInitializerError

This is raised automatically by the JVM. If there is any Exception during initialization of static variables or execution of static blocks.

public class Test {

       static int i=10/0;

public static void main(String[] args) {

System.out.println(“Hello Dear…”);

}}

Output:

java.lang.ExceptionInInitializerError

Caused by: java.lang.ArithmeticException: / by zero

at com.clarity.test1.<clinit>(test1.java:93)

Exception in thread “main”

Exception in static block : 

public class Test { 

static{

String s;

System.out.println(s.length());

}

public static void main(String[] args) {

System.out.println(“Hello Dear…”);

}}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s