so I just realized my APCS teacher will probably use the same assignment and one of my friends just posted this thread on my facebook, soooooooooooo deletin' errything
so I just realized my APCS teacher will probably use the same assignment and one of my friends just posted this thread on my facebook, soooooooooooo deletin' errything
Last edited by Marksman Bryan; 2013-02-03 at 05:44 PM.
Post the TOHApp part too. Complete code. With that debug error, you're looking at an off by one error somewhere.
poof
Last edited by Marksman Bryan; 2013-02-03 at 05:44 PM.
If I'm not wrong you create an array of Tower objects but don't initialize them. I'm gonna assume that's what causes the issue
Yes that is what I meant,
If you replace Towers with Stack in the code from your code above, so it becomes:
Public Stack[] t = new Stack[3]
then instead of t[0].adddisc
just do t[0].push(new Disc(i));
will it compile?
just make a loop and create a new object for each element of the array
Code:for(int i =0; i < 3; i++) { t[i] = new Tower(); }
That gives me:
Which indicates there is a problem with Tower.Code:Exception in thread "main" java.lang.NullPointerException at Tower.addDisc(Tower.java:11) at TOHModel.<init>(TOHModel.java:10) at TOHFrame.<init>(TOHFrame.java:7) at TOHApp.main(TOHApp.java:5) Java Result: 1
I wish I learned objects more in depth.
s is null according to the debugger, but I thought having
initialized it?Code:private Stack s; public void Tower(){ s = new ArrayListStack(); }
EDIT:
GOT IT.
I had public void Tower(), should be public Tower().
Derp mistake.
I WILL BE UPDATING THIS THREAD WITH MORE PROBLEMS, THOUGH. Thanks guys!
now to figure out how to paint the discs
Finished the rest of it last night, and added in rules on the side and finished handling exceptions.
Everything works like it should, can't get it to throw an exception, so I'm happy :) thanks again guys ~
I will be making another thread soon; I have to make an RPG game by the end of the year entirely with Java.
|
Bookmarks