返回对象数组的方法 [英] Return Object array method

查看:146
本文介绍了返回对象数组的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法返回变量在这个方法数据

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是说前pression的非法启动。有没有执行该法的方式进行,其中的数据(从传输到一个MySQL数据库来一个的ArrayList&LT;对象&gt; 在接口)传递给 [对象] ?寻找一种方法来填充数据从MySQL数据库来的JTable 行。

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.

推荐答案

错误就出现在这里:

data = {bar, code, name};

相反,构建对象持有字符串的实例的新数组:

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

然后就可以调用 addRow(数据)的DefaultTableModel 。一个完整的例子显示 TableAddTest#addRow href=\"http://stackoverflow.com/a/19472190/230513\">()

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

这篇关于返回对象数组的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆