Jump to content
  • Advertisement
Sign in to follow this  
Xiachunyi

[java] java.lang.NullPointerException

This topic is 4825 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

Hello, I was wondering what does it mean if your program displays the following error: Exception in thread "main" java.lang.NullPointerException at MainEntryPoint.main(CS Program_1.java:44) This is what it is pointing to as well as its supporting manipulation:
AmortizationTable oATable[] = new AmortizationTable[TABLE_LIMIT];
for(int loop=0; loop < TABLE_LIMIT; loop++)
{
	oATable[loop].Setup(false, 0.0, 0.0, 0.0);
}
...
class AmortizationTable
{
//Local Variables
	private float dPrinciple, dPercentageRate, dMonthlyPayment;
	
//Accessible Functions
 	public AmortizationTable()
 	{

 	}
 	
 	public void Setup(boolean Valid, double Principle, double PercentageRate, double MonthlyPayment)
 	{
 		
 	}
...
Am I somehow overunning the array of objects that I have created or something of that nature? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
You only created the array. You have to create a new instance of AmortizationTable on each index. Until you do that, your array is empty (it has a null reference on each index). So when you call the Setup() method you get that NullPointerException, because there is no object there in the first place.

Solution:

for (...)
{
oATable[loop] = new AmortizationTable();
oATable[loop].Setup(...);
}

Share this post


Link to post
Share on other sites
Thank you so much. I know I should consult Google and my programming manual but my lack of knowledge about Java makes it a little hard.

Thank you again.

Share this post


Link to post
Share on other sites
Ah, don't mention it. I've been working with Java for several years now, and I keep doing that mistake (I remember it happened some weaks ago). Sometimes I think the default constructor is being called for each array index... but Java doesn't do that.

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!