当我尝试在JComboBox中添加项目
时出现此错误不兼容的类型:ComboBox无法转换为String
这是我将数据从数据库加载到JComboBox的方法......
public final void loadProducts()
{
try
{
String sql = "SELECT * from product";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next())
{
combobox.addItem(new ComboBox(rs.getString(2), rs.getString(1)));
}
combobox.setSelectedIndex(-1);
}
catch (SQLException ex)
{
System.out.println(ex);
}
}
这是班级
public class ComboBox
{
private String key;
private String value;
public ComboBox(String key, String value)
{
this.key = key;
this.value = value;
}
@Override
public String toString()
{
return key;
}
public String getKey()
{
return key;
}
public String getValue()
{
return value;
}
}
我不知道是什么导致了它!有人可以指出我的错误吗?