سؤال

I am currently trying to add a series of objects to an arrayList each time an event happens, I use the following method :

public void nativeMousePressed(NativeMouseEvent e) {

    if(record == true)
    {
        getInfo inf = new getInfo();
        infoCtrl info = new infoCtrl();
        info.setX(e.getX());
        info.setY(e.getY());
        infor.add(inf);


    }


}

The Arraylist is global, I also have a global controller and one which I make here, I tried using both. This version of the code has only the needed lines, however in the real method I test every bit with println, each time, the values are there, but after I add the object to the arrayList, everything is back to 0, just like when the object is first created.

Can anyone see the problem in this and how to fix it?

Thank you

Note : When I print the contents of the list, i get all of the objects that I added in it, but all of their values are 0, the same as like they were just created, even though before that I have a println which shows me their values perfectly.

هل كانت مفيدة؟

المحلول

You fill the values into info and then add inf to the list.

Hint - The standard convention for Java is to hava all classes begin with a capital letter. That would mean you change getInfo to GetInfo and infoCtrl to InfoCtrl. Since you aren't following the convention, it makes it hard to tell how you are doing the list object (or is it a class) infor. (We typically find that using longer names helps keep things straight.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top