#java.lang.nullpointerexeption when trying to change a objects attributes

32 messages · Page 1 of 1 (latest)

weary pilot
#

I have a java school project that is due to tomorrow. But I suddenly keep getting an error when im trying to change an objects attributes. I am working with a program called blueJ. It gives you a better overview of the project and there is no main class since you have to create (at least one) object yourself. But I have a problem. The GUI2 class has a method in which the name attribute of the player class should be changed. Now if create objects of each class and call the method by hand I get the error java.lang.nullpointerexeption in the line in which the name of the player is being changed.

Pls anwer quickly since I will get 0 points if I don't have my fully finished project by tomorrow.
Thank you in advance.

shrewd oceanBOT
#

This post has been reserved for your question.

Hey @weary pilot! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pulsar umbra
weary pilot
#

yes when i create the player object by hand it asks me for the name etc. and i fill it in correctly

#

i have also tried if it would work if I created the player with code but i got the same result

pulsar umbra
#

I'm sure you need to create spieler objects by hand

#

for example, you create JFrame object by hand too

#

fenster2 = new JFrame("round")

#

so you also need to create a player by hands too

weary pilot
#

no with doing it by hand i mean clicking buttons in bluej

pulsar umbra
#

I mean by coding it.

#

like, spieler1 = new Spieler("name", etc);.

#

and only after that you can use that object

weary pilot
#

i get the same error

#

this is what i meant by creating it by hand

pulsar umbra
#

at which line of code?

pulsar umbra
weary pilot
#

yes before it was the line in which the name is changed but now its the line in which the object is created

#

wait nevermind

#

i think it worked

#

wait a second

#

I HAVE ABSOLUTELY NO CLUE WHY IT WORKS WHEN THE OBJECT IS CREATED WITH CODE INSTEAD OF BY HAND BUT I DONTZ CARE

#

thank you so much man

#

saved my sife

#

*life

pulsar umbra
#

you are welcome 🙂

weary pilot
#

i think that objects created by hand are somehow not recognized by java. Which means that I am absolutely fcked because my whole project is build on one class which needs to be crated by hand at the beginning

pulsar umbra
#

bluej is awful. Use at least eclipse. Intellij is better. But sometimes teachers make students use bluej. But if you don't have to use it - use at least eclipse

weary pilot
#

no we have to use it

#

but i think i found a way around this

#

ill just make an object which creates the main object and starts the game because the startgame method is in the constructor