1

I just can't seem to return the variable data in this method:

public Object[] populateTable(ArrayList<Outlet> outletList, String selection){ 
    Object[] data;
    for(int i = 0; i<outletList.size(); i++){
        if(outletList.get(i).getCity().equalsIgnoreCase(selection)){
            if(outletList.get(i).getStatus().equals("ACTIVE")){

                String bar = outletList.get(i).getBarangay();
                String code = Integer.toString(outletList.get(i).getCode());
                String name = outletList.get(i).getName();

                data = {bar, code, name};                      
            }   
        }               
    }
    return data;
}

Netbeans is saying illegal start of expression. Is there a way to execute this method wherein data (coming from a mysql database transferred to a ArrayList<object> in an interface) is passed to an Object[]? Finding a way to populate JTable rows with data coming from a mysql database.

1 Answer 1

3

The error arises here:

data = {bar, code, name};

Instead, construct a new array of Object to hold instances of String:

data = new Object[]{bar, code, name};

Then you can invoke addRow(data) on your DefaultTableModel. A complete example is shown here in TableAddTest#addRow().

image

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.