Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] java.lang.NullPointerException! Help!

Started by PixolMaster Aug 19, 2005 at 7:54 PM 2 replies 1k views
Original Post
PixolMaster
PixolMaster
Hi! I'm pretty new to Java (I've always used C++), and I've run into a bit of a problem... Here's the code:
 
Triangle[] triArray;   // The array used for depth testing when adding triangles to the draw buffer

...
...

triArray = new Triangle[drawBuffer.size()];
drawBuffer.toArray(triArray);

This returns the following runtime error: (you guessed it...) java.lang.NullPointerException! I can't figure out what is causing the problem! I've tried initializing the variable triArray in as many ways as I can think of, and nothing eliminates the error! It's driving me mad! Any help would be greatly appreciated. Thanks for your time. ~~ Alex
widggman
widggman
Check in the exception description to see the line with the Null Pointer.
Maybe drawBuffer is not initialize.

you have to do something like that:
drawBuffer = new

In Java, every class has to be created with "new". In C++, you can create an instance of a class without memory allocation.

Check around that...

PixolMaster
PixolMaster
Quote:
Original post by widggman
Check in the exception description to see the line with the Null Pointer.
Maybe drawBuffer is not initialize.

you have to do something like that:
drawBuffer = new

In Java, every class has to be created with "new". In C++, you can create an instance of a class without memory allocation.

Check around that...


Ahh you were right! Thank you so much! Ahh the joys of learning a new language.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.