We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to run this, but i cannot get the object to initialize.
class StoreStuff
{
private ArrayList<String> botle ;
private ArrayList<String> apple ;
public StoreStuff ( ArrayList<String> botle, ArrayList<String> apple ) {
this.botle = botle;
this.apple = apple;
}
void addApple() {
apple.add("Jonagold");
}
}
void draw () {
final StoreStuff stuffs = new StoreStuff();
stuffs.apple.add("Jonagold");
println(stuffs.apple);
}
Answers
Hello, you defined one constructor in your class:
It takes two
ArrayList<String>
as arguments. But when creating the object, you pass nothing as arguments.So the, very clear, message tells you that there is not a constructor with this signature (the kind and order of arguments).
You can either build the object with the expected parameters, or define a constructor that takes no arguments.
:)
ps: Do you really wants to recreate the object 60 times each second in draw?
Nope, it that would be a bit redundant no? I expect the information to stay in the class without it needing to be recreated all the time.
So you should not declare it inside
draw()
like:
}
Have you forgotten your previous StringList thread already? :-\"
http://forum.processing.org/two/discussion/7657/how-to-put-a-stringlist-in-a-constructor
yehaaa, that works!, many many thanx! ;) you made my day :)
:) I don't know what you are looking for, but if you intent to pass the apples alone, perhaps you only need the Lists inside the class not the outside ones...
perhaps you are looking for this? (I changed the behaviour of the addApple to don't always add "JonasGold")
edit2: and changed the constructor also.
GoToLoop: No, I haven't forgotten about it, in fact that is from where I started!!, but there was something there that I could not grasp, I was missing something.
_vk : Thx, this gives me all the functionality I need :)
Well, if you don't tell us, we can't guess it, right? ;)
Well the thing in question was that I didn't knew how initialize the class, or how put any values/strings into it.
new StoreStuff();
<StoreStuff's reference>.addBottle("Katniss", "Magnetic_Garden")
Alternatively, w/o using some "setter" method:
<StoreStuff's reference>.bottles.append("Katniss");
<StoreStuff's reference>.bottles.append("Magnetic_Garden");
Thx Dude!!, this is all of great help!