私は通常の辞書のようなリストを表示する辞書についてのプロジェクトを持っています。私はプログラムを始めたときの課題は辞書。 java.lang.ArrayStoreException
など我々はtreeDictionary、HashMapのように、単語を表示するにはカップルの実装を使用するべきであると、私たちは利用したい実装の種類を選択する必要があり、その後、I data.txtを選択してください(このデータでは、最初の配列のドイツ語と2番目の英語の単語があります)
JTextAreaに表示された単語の後に、プログラムを終了してもう一度起動して別の実装やデータなどを選択してはいけません。
しかし、私は第二の実装を選びました後、日食は、スレッドでのエラー
例外 "AWT-EventQueueの-0" java.lang.ArrayStoreExceptionat java.lang.System.arraycopy(ネイティブメソッド)
私を示してい- 私のensureCapasityメソッドに焦点を当てています。
これは私のコードです:
{
Component myFrame = null;
static double startTime = 0;
int data[], summeEntry ;
static int size;
static String[] deutsch = new String[16000];
static String[] englisch = new String[16000];
private void ensureCapacity(String o[],int newCapacity){
if(newCapacity < size) {
return;
}
String [] a = o;
data = new int[newCapacity];
System.arraycopy(a, 0, data, 0, size);
}
//open file
public void read(File f) {
LineNumberReader in = null;
try {
in = new LineNumberReader(new FileReader(f));
String line;
int i = 0;
while ((line = in.readLine()) != null) {
String[] sf = line.split(" ");
if (sf.length == 2) {
if(size >= deutsch.length){
ensureCapacity(deutsch, size*2);
ensureCapacity(englisch, size*2);
}
//kamusGUI
kamusGUI.dt.insert(sf[0], sf[1]);
deutsch[i] = sf[0];
englisch[i] = sf[1];
size++;
i++;
} else if (sf.length == 3) { //I just copy from the first if. Then it can calculate the actually number of words
if(size >= deutsch.length){
ensureCapacity(deutsch, size*2);
ensureCapacity(englisch, size*2);
}
kamusGUI.dt.insert(sf[0], sf[1] + sf[2]);
deutsch[i] = sf[0];
englisch[i] = sf[1] + sf[2];
size++;
i++;
} else if(sf.length >= 3){
//wenn ein deutsches Wort mehr als 2 Bedeutungen hat
JOptionPane.showMessageDialog(myFrame, "Hallo, english more than 2 words");
}
}
//to show your entries in output
kamusSearchDelete.tOut.setText(kamusGUI.dt.toString());
//to show how many entries you have from your dictionary
kamusSearchDelete.stsEntry.setText("Total entr(y/ies): " + size + " words");
in.close();
} catch (IOException ex) {
System.out.println("open canceled");
}
}
public static void save(File f) {
PrintWriter out = null;
try {
out = new PrintWriter(f);
out.println(kamusGUI.dt.toString());
out.close();
} catch (IOException ex) {
System.out.println("save canceled");
}
}
私はmainメソッドを呼び出すために、既に別のJButtonを構築しています(私が言うことができ、私はこのボタンからプログラムをリセットしてみてください)、我々は別のimplmentationを選択することができます。しかし、それは正しく動作しません。たぶん皆さんは何か考えているのですが、配列とどうすればいいですか? 1つのアドバイスやアイデアごとに非常に感謝しています。
IVEは多分エラーを追加君たちはそれ
Exception in thread "AWT-EventQueue-0" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at aufgabe1.kamus.ensureCapacity(kamus.java:35)
at aufgabe1.kamus.read(kamus.java:50)
at aufgabe1.kamusMenu.actionPerformed(kamusMenu.java:156)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
完全なトレースバックを含む例外を質問自体に追加してください。 –
@Antti iveはそれを追加しました –