0
I need some guidance on a problem with the code I'm working on (Java). [solved]
The code's URL: • https://code.sololearn.com/cnomod6HKBDS
23 Réponses
+ 4
The problem is you're trying to declare types that don't exist. Triangle, Rectangle, and Circle are not real variable types, and is your problem. You have no real method of creating a circle, triangle, or a rectangle.
+ 1
back away from it and chillax Cl Ran and it will come to you...
+ 1
Cl Ran
Do I understand this right? You need to write the classes circle, triangle and rectangle? Or are they imported? If so, from where?
+ 1
Cl Ran But so I can't test your code.
I just can guess that there is something wrong with alignHead().
before you call this method you should check if head, body and leg not null.
+ 1
Cl Ran
Your constructor:
public StickFigure()
{
super();
this.setXPos(25); //sets starting position towards bottom left of Shapes window
this.setYPos(220);
this.head = new Circle(30,OUColour.PINK);
this.body = new Triangle(50,50,OUColour.RED);
this.leg = new Rectangle(6,50,OUColour.PINK);
this.alignAll();
Maybe I have found the problem:
You are calling at first setXPos(25). Now look into setXPos() -> in the setter you are calling alignAll();
But at this time head, body and legs are null.
First create head, body and legs and call then the setter for x and y.
Or don't use the setters inside the constructor. Just write xpos = 25 and ypos = 220
+ 1
Thank you for your time and solution, I will into it more to and reply tommorrow
+ 1
circle, triangle, and rectangle arent types, see clock applet.
+ 1
Xm
0
This code about creating stickfigure with shapes that represents so far.
When I try to create a new stickfigure the error as follows
java.lang.NullPointerException
in StickFigure.alignHead(StickFigure.java:106)
in StickFigure.alignAll(StickFigure.java:136)
in StickFigure.setXPos(StickFigure.java:45)
in StickFigure.<init>(StickFigure.java:27)
in (OUWorkspace:1)
0
Cl Ran It is not the complete code, right?
0
Yes it is not complete yet, I'm just frustrated with it.
0
they are imported from so dont worry about the shapes , I use bluej
0
so far I sorted some issues at the moment
0
Cl Ran
I made a small example. Hope this helps.
https://code.sololearn.com/cxUk45CLqv11/?ref=app
0
heres the latest, the issue is with the alignment of head, body and leg
0
Haven't you shared the code or I can't see it?
0
What problem?
0
He shared his code. One problem I'm seeing is that he doesnt have the right packages imported. Secondly, after messing with his code I dont think Sololearn has deployed the packages required (javafx). Looks like to do it right he'd need to develop his stickfigure on a real JDE, but Sololearn wouldnt be able to run it regardless.
0
Here is the solution