Hi there!

I have some problem with java. I developing a multiplayer applet, there a class called userServer registry new users and logging in other users. the problem is, that I don't
know how to append in a array.

user Users[];
int cnt=0;
Users[cnt] = new user("emorjon2", "password");
cnt++;

is that the right way to append a item to an array??;:?: I myself don't think so, because
when I'm running the program it will be compiled without problem,
but then it print's out NullPointerException, what that means... :confused:

What you have is OK, just one thing missing...
you define a "users" variable, but you don't actually create an array, so the variable just contains a null pointer. You need something like
user Users = new user[99]; // creates an array with 99 slots for users

nb 1 Java convention is class names begin with a capital letter, variables begin with a lower-case letter - if you reverse this its confusing for other people

nb 2 Most people would use an ArrayList here rather than an array so they don'thave to worry about how big it is.

thank's ^^

Mark this solved please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.