Jump to content
  • Advertisement
Sign in to follow this  
PixolMaster

[java] java.lang.NullPointerException! Help!

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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 <DrawBufferClass>

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...

Share this post


Link to post
Share on other sites
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 <DrawBufferClass>

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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yepp - you have created array object, but not elements in that array which seems to be objects as well and thus need to be created with new as well.

something like this:



triArray = new Triangle[drawBuffer.size()];
for(int i=0; i<

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!