ExceptionInInitializerError ?
What is the error all about ? Why is this coming with this program ?
I know there is some mistake in static block.
CertkillerTe2.java
public class CertkillerTe2 {
static int[] a; // static variable
static {
a[0] = 2;
} // static block
public static void main(String[] args) { }
}
Output :
D:\>javac CertkillerTe2.java
D:\>java CertkillerTe2
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at CertkillerTe2.<clinit>(CertkillerTe2.java:4)
[606 byte] By [
Tatona] at [2007-10-3 3:00:20]

You need to iniialse the array. The following works OK
public class CertkillerTe2 {
static int[] a = new int[10]; // static variable
static {
a[0] = 2;}
//} // static block
public static void main(String[] args) { }
}
Fo primitive arrays like this the following quote is informative. There are other structures that are dynamic and usually more useful than a int[] or other primitive array.
"Unlike some programming languages, in Java, arrays have to be specifically created (or declared) and are of a definite size. It is not possible to change the size of an array once you have declared its size, you can, of course, copy the contents to another, larger, array."
Message was edited by:
nerak99
> Fo primitive arrays like this the following quote is
> informative. There are other structures that are
> dynamic and usually more useful than a int[] or other
> primitive array.
Note that those structures can not handle primitives (even though it may look that way through autoboxing in 1,5,0).