【发布时间】:2013-02-18 23:47:03
【问题描述】:
getStrings() 方法给了我一个ClassCastException。谁能告诉我应该如何获得模型?谢谢!
public class HW3model extends DefaultListModel<String>
{
public HW3model()
{
super();
}
public void addString(String string)
{
addElement(string);
}
/**
* Get the array of strings in the model.
* @return
*/
public String[] getStrings()
{
return (String[])this.toArray();
}
}
【问题讨论】:
-
你的
toArray方法在哪里? -
这是我调用的 DefaultListModel 的一种方法。我不应该使用“这个”
-
他用的是超类的方法。但它不返回字符串数组,而是返回对象数组。所以这是你的问题。对待它是什么,一个对象数组。
-
有什么办法可以将其转换为字符串数组?