ton1
ton1

Reputation: 7628

Java Simple Reference : Error

Actually I don't know what is the problem. Please understand me that I'm bigginer. Let me show you code :

In Class A, There is a code below :

jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"aaa", "aaa", "aaa", "aaa"},
                {"bbb", "bbb", "bbb", "bbb"},
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));

In Class B, Adding another table row. like :

    DefaultTableModel model  = (DefaultTableModel)ToddlerGUI.jTable1.getModel();    
    model.addRow({"ccc","ccc","ccc","ccc"});

But Eclipse tells me there is an error(you know, red line)

The method addRow(Vector) in the type DefaultTableModel is not applicable for the arguments (String, String, String, String)

Anyone know what is problem?

Upvotes: 0

Views: 298

Answers (2)

LHA
LHA

Reputation: 9655

Syntax { "ccc","ccc","ccc","ccc" } used ONLY for declaration. NOT use for passing parameter in a method.

For example:

String[] strs = { "ccc","ccc","ccc","ccc" }; // VALID

BUT

model.addRow( {"ccc","ccc","ccc","ccc" } ); // INVALID

Upvotes: 2

sakthisundar
sakthisundar

Reputation: 3288

Change the method invocation model.addRow({"ccc","ccc","ccc","ccc"}); to model.addRow(new String[]{"ccc","ccc","ccc","ccc"});. That should do for you.

Upvotes: 1

Related Questions