• Advertisement
Sign in to follow this  

[java] java.lang.NullPointerException

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

basically I've got a java project which contains 2 classe: public class user { String user; String real_name; String character_name; int character_age; } and public class principal{ void myFunction() { user[] TheUser; [......] TheUser=new user[10]; TheUser[0].user=user; TheUser[0].character_name=character_name; TheUser[0].real_name=real_name; TheUser[0].character_age=Integer.valueOf(character_age); } } when i try to execute the above lines, i've got an java.lang.NullPointerException, the problems come from TheUser.... if someone has a clue, let me know. cheers !!

Share this post


Link to post
Share on other sites
Advertisement
All you did with the array is to create a new array of user objects. You didn't create any new user objects. You need a for loop.

for( i = 0; i < TheUser.length; i++ ) {
TheUser[ i ] = new user();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by GKW
All you did with the array is to create a new array of user objects. You didn't create any new user objects. You need a for loop.
*** Source Snippet Removed ***


Oh really!!!, thanks for the tips !!!

Share this post


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

  • Advertisement