在做的是一个SWT的东西。我的想法是从数据库中获取一个ResultSet,然后给combo赋值,代码如下:               try {
ResultSet resultSet;
resultSet = (ResultSet) DbOperate.getColumn();
int i = 0;
String[] category = new String[10];
while(resultSet.next())
{
category[i++] = resultSet.getString("category");
}
groupCombo.setItems(category);
} catch (SQLException e) {
e.printStackTrace();
}但运行时(在红色字体那一行)出现如下错误: Argument not valid
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.error(Unknown Source)
at org.eclipse.swt.widgets.Combo.setItems(Unknown Source)不知道为什么会出错,而且验证过,可以从数据库中获取到数据,另外,我试过如果按如下方式赋值,却没有错:
                    String[] category = new String[]{"默认","同学","朋友","家人","公司"};
                    groupCombo.setItems(category);
纠结很久了,可能是我的想法可能错了,或者有没有别的方法,可以从数据库获取数据给combo赋值。劳请达人指教,谢谢!

解决方案 »

  1.   

    问题是Combo中的值不能重复,这个你可以保存在List中,再使用List.toArray(new String[0]),对Combo赋值
      

  2.   

    问题是Combo中的值不能重复,这个你可以保存在List中,再使用List.toArray(new String[0]),对Combo赋值
      

  3.   

    while(resultSet.next()) 

    category[i++] = resultSet.getString("category"); 
    groupCombo.addItem(category); 

    LZ你看这样可以吗?
      

  4.   

    就我所知 SWT中的Combo好像没有addItem这个方法
      

  5.   


    我测试过了,category中的值没有重复,但同样要出错。
      

  6.   

    你的数组中有10个值吗? if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
    for (int i=0; i<items.length; i++) {
    if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
    }还是上面的建议,保存到List中,因为你不清楚ResultSet的长度,而使用List的toArray能保存转换的数组每个值都不是空
      

  7.   

    原来不是错在数组上,而是用错了Combo的方法,太粗心了...anyway,谢谢楼上各位的帮助了!