Sign in to follow this  
jolyqr

[java] java.lang.NullPointerException

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this