Kann mir jemand bei einem Informatik Java Projekt helfen?
Hi,
für die Schule muss ich in Informatik ein einfaches Textadventure in Java (BlueJ) coden, Thema “Magier und Schwertkämpfer”. Beim Erstellen eines neuen Objekts aus einer der beiden Klasse “magier” und “schwertkämpfer” über ein Objekt der Klasse “gamemanager” hakt es bei mir und ich habe nicht die expertise zu sagen, warum kein neues Objekt erstellt werden kann. Die beiden Klassen magier und schwertkämpfer bekommen die Grundattribute aus der Klasse “rolle” vererbt. Nach der Auswahl der Klasse soll auch ein Name ausgewählt werden können, die Attribute “Dm” und “Hp” sind je nach Klasse vorgegeben.
(Die Konstruktoren und Methoden von magier und schwertkämpfer sind gleich)
Where is the Main, where the whole thing begins?
It looks like you just want to access a player object, but you didn’t even create one. That’s why this would be zero.
The constructor of the sword fighter should also be public here, otherwise you have an access violation.
But best of all, you put all your code somewhere and show it to us – so it is enormously strenuous and a price game.
//EDIT: I see individual mistakes, but as I said, they are really hard to find;
You put the player and then call the constructor again? I think he might fly you out of here.
Oh, that’s badly named from my side. the “constructor” that you see is a method in the game manager that has the same content as the one that came up with it. I had thought that the creation of an object within the if query might make it somehow accessible only within this query (like temporary variable within such querying or grinding).
I can’t answer that question, I’m sorry. ^^
The code is unreadable for me, then only half-gare answers come out.
Since it all plays in the same package, it should not be a problem.
Well, I didn’t see that.
That’s why I usually ignore such questions. It’s just exhausting. ^^
https://docs.google.com/document/d/e/2PACX-1vRhBL_7Q9vi2AuZuQoKfeEnxsyWLHsZt3ZFb0Yn8OtN7gYSQpwtaG5zrsQOLePTuwpSpM9JTfrFV4v/pub
I don’t know any better services to link the code
But thank you for the already given tips
you can also write the code into your question, but please use the “Sources” option! And also adequately subdivide it
Right, like a puzzle. 😀
Some questioners seem to see this rather as an exciting puzzle task for the GF audience 🙂
The field “player” in the class gamemanager is never set. As the error message already says clearly: it is zero, so the NullPointerException attempts to read the field spieler.attacke1.
In front of this, you set various objects (“player”, “gegner”), but only as local variables that are never used.
You have to put a public in front of the constructor. In addition, you did not define the field “attacke1”. Then it should go.
Edited: Excuse my stupidity.
What the mistake can be is that you have to do in the constructor of hard fighter you, “super.attacke1”.
Which one?
where there is none, with the heavy fighter. The error, however, is that it has not defined the field attacke1.
Wrong, he must write super.attacke1
He put the player in a picture. Is not more comfortable on the PC. Screenshots of Code just. x)
The error is hard to read on the phone. But it’s right. Then what in the main() does not have to vote
That’s right. It’s not the mistake. The error will be that the player has not been defined “this.player is null” – if only your error had happened, a message for access violation would have appeared, not that the player is zero.