N
N
Neonoviiwolf2016-08-15 23:03:18
Java
Neonoviiwolf, 2016-08-15 23:03:18

How to access from ArrayList object properties in JAVA?

Kind
In the AS3 language, I know how to get access, but it doesn’t work by analogy with JAVA. Let there be a Label, it has an id and it (Label) is added to the ArrayList. How can I find out what is stored in id? It is necessary to compare the ID with those in the database

if (resultSet.getInt(1) == arrayList.get(i).getId){}//по аналогии с as3
//arrayList[i].getId - так бы выглядел доступ в as3

if (resultSet.getInt(1) != arrayList.get(i).getId()) {
                        Label label = new Label();
                        label.setId(String.valueOf(resultSet.getInt("id")));
                        label.setText(resultSet.getString("nameProduct"));

                        arrayList.add(label);
                        root.getChildren().add(label);
                    }

Error:(131, 60) java: cannot find symbol
symbol: method getId()
location: class java.lang.Object

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-08-15
@Neonoviiwolf

Well, probably for the Label method, if the field id is private, you need to write a getter

public class Lebel {
    private long id;

   public void setId(long id) {
       this.id = id;
   }
   public long getId() {
       return id;
   }
}

and then access the id using the method
maybe they just forgot the parentheses at the end that this is a method

G
GavriKos, 2016-08-15
@GavriKos

So what's the question then? get does work. Only getID looks strange, but oh well.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question