null pointer exception ?

ok, i am coding a server- client game like runescape and its all multithreaded, but when other people login during a thread that is supposed to make something global for all players, i get this error

http://img2.freeimagehosting.net/uploads/0ecb4d2ba7.png

it happens whenever they login before their character gets set up...i even put anti-null in the coding where its messing up

publicvoid replaceObject(int x,int y,int typeID,int orientation,int tileObjectType){//Makes Global objects

for (Player p : server.playerHandler.players){

if(p !=null){

client person = (client)p;

if((person.playerName !=null || person.playerName !="null")){

person.setObject(x, y, typeID, orientation, tileObjectType);

}

}

}

}

publicvoid setObject(int objectX,int objectY,int NewObjectID,int Face,int ObjectType){

outStream.createFrame(85);

outStream.writeByteC(objectY - (mapRegionY * 8));

outStream.writeByteC(objectX - (mapRegionX * 8));

outStream.createFrame(101);

outStream.writeByteC((ObjectType<<2) + (Face&3));

outStream.writeByte(0);

if (NewObjectID != -1){

outStream.createFrame(151);

outStream.writeByteS(0);

outStream.writeWordBigEndian(NewObjectID);

outStream.writeByteS((ObjectType<<2) + (Face&3));

//FACE: 0= WEST | -1 = NORTH | -2 = EAST | -3 = SOUTH

//ObjectType: 0-3 wall objects, 4-8 wall decoration, 9: diag. walls, 10-11 world objects, 12-21: roofs, 22: floor decoration

}

}

basically, whenever a thread is going and someone logs in i get that null pointer exception. any suggestions?

Message was edited by:

ByronTheOmnipotent

Message was edited by:

ByronTheOmnipotent

[2902 byte] By [ByronTheOmnipotenta] at [2007-11-27 11:20:53]
# 1

It's happening in that createFrame method, like the stack trace says. What is it doing?

CeciNEstPasUnProgrammeura at 2007-7-29 14:45:16 > top of Java-index,Java Essentials,New To Java...
# 2

Looks like your anti-null trap is to ironic blame. You've said "if the person's name isn't null or it isn't the string literal "null", get on with things. So basically, if player.playerName is null, then it is allowed in by your second condition, because null is not the string literal "null". I think you meant the logical and operator rather than or. But comparing strings like that is bad and wrong anyway, use .equals().

georgemca at 2007-7-29 14:45:16 > top of Java-index,Java Essentials,New To Java...
# 3

More design feedback: a setObject method should do just that: set an object. This one obviously isn't just a dumb setter, so you ought to give it a better name.

CeciNEstPasUnProgrammeura at 2007-7-29 14:45:16 > top of Java-index,Java Essentials,New To Java...
# 4

I was in the middle of editing my post to include the fact that I never followed your link, when Rene replied to me :-)

What I spotted will be a problem, too, all the same

georgemca at 2007-7-29 14:45:16 > top of Java-index,Java Essentials,New To Java...
# 5

alriht thanks a lot george it was the || operator, cecinest thanks for the advice man, yah i kinda suck at naming stuff

ByronTheOmnipotenta at 2007-7-29 14:45:16 > top of Java-index,Java Essentials,New To Java...