fr33zex
fr33zex

Reputation: 61

Observable List

when trying to declare a new ObservableList:

ObservableList<Account> userAccounts = new FXCollections.observableArrayList();

I am getting an error at observableArrayList(); which says:

cannot find symbol, symbol: class observableArrayList, location: class FXCollections.

Here are my import statements

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

And here is my method

public ObservableList<Account> getUsersAccounts(int memberID) { 
    ObservableList<Account> userAccounts = new FXCollections.observableArrayList();

    try {     
        Statement stmt = conn.createStatement();            
        String sql = "SELECT * FROM account WHERE member_id='" + memberID + "'";            
        ResultSet rs = stmt.executeQuery(sql);

        while(rs.next()) {
            Account account = new Account(rs.getInt("member_id"), rs.getString("account_type"), rs.getDouble("balance"));
            userAccounts.add(account);
        }
    } catch (SQLException ex) {
        Logger.getLogger(JDBCManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return userAccounts;
}

What am I missing, why can't I declare a new ObservableList?

Upvotes: 5

Views: 5427

Answers (2)

parsa
parsa

Reputation: 985

change

ObservableList<Account> userAccounts = new FXCollections.observableArrayList();

to

ObservableList<Account> userAccounts = FXCollections.observableArrayList();

Upvotes: 7

Andrew
Andrew

Reputation: 49606

An instance can be created directly by using a constructor or implicitly by calling a method where this constructor can be invoked.

In your case, it's a static method. Have a look at these techniques:

List<String> a = new ArrayList<>();
List<String> b = Lists.createList();

class Lists {
    public static <T> List<T> createList() {
        return new ArrayList<>();
    }
}

Upvotes: 7

Related Questions