私はJavaで初めてJTablesとVectorsをいじくり回していて、興味深い問題にぶつかりました。私のコードは正しくコンパイルされますが、実行しようとすると、次の例外が発生します。
スレッド"main"の例外java.lang.ClassCastException:java.lang.Stringをjava.util.Vectorにキャストできません
キャストしているところがどこにも見当たらないので少し戸惑います。
Vector<String> columnNames = new Vector<String>();
columnNames.add("Tasks");
Vector<String> testing = new Vector<String>();
testing.add("one");
testing.add("two");
testing.add("three");
table = new JTable(testing, columnNames); // Line where the error occurrs.
scrollingArea = new JScrollPane(table);
私の目標はJPanelsのテーブルを作成することですが、<taskPanel>のVectorを使用しようとすると、同じタイプのエラーが発生します。JPanelを拡張するクラスは次のとおりです。
class taskPanel extends JPanel
{
JLabel repeat, command, timeout, useGD;
public taskPanel()
{
repeat = new JLabel("Repeat:");
command = new JLabel("Command:");
timeout = new JLabel("Timeout:");
useGD = new JLabel("Update Google Docs:");
add(repeat);
add(command);
add(timeout);
add(useGD);
}
}