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)

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
16 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Dultus, UserMod Light

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.

Dultus, UserMod Light
Reply to  DrJekll

I can’t answer that question, I’m sorry. ^^
The code is unreadable for me, then only half-gare answers come out.

jo135
1 year ago

The constructor of the sword fighter should also be public here, otherwise you have an access violation.

Since it all plays in the same package, it should not be a problem.

Dultus, UserMod Light
Reply to  jo135

Well, I didn’t see that.

That’s why I usually ignore such questions. It’s just exhausting. ^^

ChadThunderhahn
1 year ago
Reply to  DrJekll

you can also write the code into your question, but please use the “Sources” option! And also adequately subdivide it

Dultus, UserMod Light

Right, like a puzzle. 😀

jo135
1 year ago

Some questioners seem to see this rather as an exciting puzzle task for the GF audience 🙂

jo135
1 year ago

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.

ChadThunderhahn
1 year ago

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

Dultus, UserMod Light

Which one?

ChadThunderhahn
1 year ago

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

Dultus, UserMod Light

He put the player in a picture. Is not more comfortable on the PC. Screenshots of Code just. x)

ChadThunderhahn
1 year ago

The error is hard to read on the phone. But it’s right. Then what in the main() does not have to vote

Dultus, UserMod Light

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.