Home arrow static arrow Java Programming [Archive] - static initializer error
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - static initializer error
This topic has 32 replies on 3 pages.    1 | 2 | 3 | Next »

Posts:91
Registered: 4/17/03
static initializer error  
Jun 27, 2004 5:51 AM



 
hi guys,
can anyone explain what might cause the following error?

i have the following classes

class BonesPlayLevel {
...
// execution reaches here
ObjFigure.initJointedModel();
...
}

class ObjFigure {
...
public static void initJointedModel() {
// execution does not reach here
initJointedModelList(myVecs);
}
...
}

and when i try and run i get the following error message:

java.lang.Error: Static initializer: java.lang.NullPointerException
java.land.Error

cheers
spob
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 6:47 AM (reply 1 of 32)



 
A static initializer looks like this
static {    // ... <your code here> ...}
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 8:02 AM (reply 2 of 32)



 
ok

myVecs (see above code) is initialised using

static protected final int[] myVecs = {
+ ( (0 << 16) | 19660), - ( (1 << 16) | 0), + ( (0 << 16) | 64764), (0 << 8) | 0,
...
}

could this then be the problem?

but i still dont understand why the error is thrown where it is?
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 8:05 AM (reply 3 of 32)



 
when do static initializers get executed?
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 8:22 AM (reply 4 of 32)



 
That's not a static initializer, that's initializing a static variable. Here's a static initializer
static int blah;static {    blah = 14; }
I'm not sure when they get executed, but I've always assume it was just after static variables were initialized.
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 8:24 AM (reply 5 of 32)



 
Maybe this will be clearer
static int blah;static {    for (int i=0;l i<10; i++) blah += i; }
If you don't have one of these in you code, I might be reading something into the error which is not there. You might consider posting your code.
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 8:39 AM (reply 6 of 32)



 
isnt

static int blah;

a static variable like myVecs?

the code is very long and will be of no use to anyone for compiling unless they also download other libraries, which is why i did not include it int he OP.

the code i am trying to run is an example to demonstrate a 3d graphics library, so i would expect it to work!
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 8:42 AM (reply 7 of 32)



 
as far as i can tell all static references in the code are used to initialise static variables or in static methods, there are no static initializers as you describe them!
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 8:52 AM (reply 8 of 32)



 
OK. How about posting the first ten lines of the stack trace and the relevent lines from your code. Each line in the stack trace has a line number reference to your code.
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 8:53 AM (reply 9 of 32)



 
Some of the lines of the stack trace are not going to be your code. Don't worry about those.
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 9:16 AM (reply 10 of 32)



 
its ok i understand how to debug, and how the stack trace works.

i am running this in JBuilder, here is the output produced

D:\Nokia\Devices\Series_60_MIDP_Concept_SDK_Beta_0_3_1_Nokia_edition\bin\emulator.exe -classpath "E:\javaApps\MIDlets\mlj3d_exbones\classes;D:\MLJ3D\v1.0.1dev\jars\mljFrame.jar;D:\MLJ3D\v1.0.1dev\jars\mljRender.jar;" -Xdevice:Series_60_MIDP_Concept_SDK_Beta_0_3_1_Nokia_edition -Xdescriptor:"E:\javaApps\MIDlets\mlj3d_exbones\jad-temp\ExBones.jad"

java.lang.Error: Static initializer: java/lang/NullPointerException
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 9:19 AM (reply 11 of 32)



 
oh and the relevent code as far as i can tell from my own debugging has already been posted.
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 9:28 AM (reply 12 of 32)



 
Here's the only other instance of that error I can find on the forums
http://forum.java.sun.com/thread.jsp?forum=82&thread=522737

Interestingly, it is also MIDP. My guess would be that one of the classes you are using is having a problem. The only thing I can suggest is to start putting System.out.println("Test Point 1"); statements in to narrow down what class is causing the problem.
 

Posts:8,813
Registered: 10/4/00
Re: static initializer error  
Jun 27, 2004 9:38 AM (reply 13 of 32)



 
By the way, static initializers run when the class is loaded. Before any instance of the class is created. This means the static initializer of whichever class is causing the problem is probably depending on a static variable from another class which is null.

I hope this helps and doesn't just muddy the waters. It's hard for me to help without your code. I don't see anything in your posted code which would cause a class to be loaded.
 

Posts:91
Registered: 4/17/03
Re: static initializer error  
Jun 27, 2004 11:28 AM (reply 14 of 32)



 
yeah i have tried the System.out.println thing and didnt get very far, thats why i posted, cheers fort he help any way, now i understand the error a bit better i may be able to sort somehting

spob
 
This topic has 32 replies on 3 pages.    1 | 2 | 3 | Next »