I need some guidance on a problem with the code I'm working on (Java). [solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

25th Jan 2020, 5:22 PM
Cl Ran
Cl Ran - avatar
23 Answers
+ 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.
26th Jan 2020, 5:25 PM
c0dezer019
c0dezer019 - avatar
+ 1
back away from it and chillax Cl Ran and it will come to you...
25th Jan 2020, 5:53 PM
BroFar
BroFar - avatar
+ 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?
25th Jan 2020, 5:55 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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.
25th Jan 2020, 6:09 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
25th Jan 2020, 9:10 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you for your time and solution, I will into it more to and reply tommorrow
25th Jan 2020, 9:14 PM
Cl Ran
Cl Ran - avatar
+ 1
circle, triangle, and rectangle arent types, see clock applet.
26th Jan 2020, 2:27 AM
AW4
AW4 - avatar
+ 1
Xm
27th Jan 2020, 1:18 PM
Refyzer.
Refyzer. - avatar
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)
25th Jan 2020, 5:35 PM
Cl Ran
Cl Ran - avatar
0
Cl Ran It is not the complete code, right?
25th Jan 2020, 5:46 PM
Denise Roßberg
Denise Roßberg - avatar
0
Yes it is not complete yet, I'm just frustrated with it.
25th Jan 2020, 5:49 PM
Cl Ran
Cl Ran - avatar
0
they are imported from so dont worry about the shapes , I use bluej
25th Jan 2020, 6:00 PM
Cl Ran
Cl Ran - avatar
0
so far I sorted some issues at the moment
25th Jan 2020, 8:09 PM
Cl Ran
Cl Ran - avatar
0
Cl Ran I made a small example. Hope this helps. https://code.sololearn.com/cxUk45CLqv11/?ref=app
25th Jan 2020, 9:42 PM
Denise Roßberg
Denise Roßberg - avatar
0
heres the latest, the issue is with the alignment of head, body and leg
26th Jan 2020, 4:41 PM
Cl Ran
Cl Ran - avatar
0
Haven't you shared the code or I can't see it?
26th Jan 2020, 7:33 PM
Kavoos Salahi
Kavoos Salahi - avatar
0
What problem?
27th Jan 2020, 6:55 AM
Amit
Amit - avatar
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.
27th Jan 2020, 7:51 AM
c0dezer019
c0dezer019 - avatar
0
Here is the solution
27th Jan 2020, 8:32 AM
VVill
VVill - avatar
0
Brian He is using bluej. Cl Ran Did you solved the problem with nullpointerexception? Or did you find more bugs?
27th Jan 2020, 8:42 AM
Denise Roßberg
Denise Roßberg - avatar