also habe ich ein Projekt, das über ein Wörterbuch ist, um eine Liste wie ein normales Wörterbuch zu zeigen. Die Herausforderung ist, sollten wir ein paar Implementierungen verwenden, die Wörter zu zeigen, wie treeDictionary, HashMap und etc.Wörterbuch mit verschiedenen Implementierungen; java.lang.ArrayStoreException
Wenn ich das Programm gestartet wird, muss ich wählen, welche Art der Implementierung wir verwenden wollen, und dann habe ich wähle die data.txt (in diesen Daten haben wir die deutschen Wörter für das erste Array und englische Wörter für das zweite)
Nachdem die Wörter auf der JTextArea angezeigt wurden, möchte ich diese Option haben, dass der Benutzer Schließen Sie das Programm nicht und starten Sie es erneut, um eine andere Implementierung und die Daten usw. auszuwählen.
Aber nachdem ich die zweite Implementierung choosed, Eclipse zeigt mir einen Fehler
Exception in thread "AWT-Eventqueue-0" java.lang.ArrayStoreExceptionat java.lang.System.arraycopy (native Methode)
- Es konzentriert sich auf meine Methode secureCapasity.
Dies ist mein Code:
{
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");
}
}
ich bereits gebaut haben eine andere JButton das Hauptverfahren zu nennen (was ich sagen kann, ich versuche, das Programm über diese Schaltfläche zum Zurücksetzen) und wir können eine andere implmentation wählen . Aber es funktioniert nicht richtig. Vielleicht habt ihr eine Ahnung, was ich mit dem Array machen soll? Ich bin sehr dankbar für jeden einzelnen Rat oder Idee.
ive hinzugefügt, um die Fehler vielleicht wollen Sie Jungs es
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)
Fügen Sie die Ausnahme mit dem vollständigen Traceback in die Frage selbst hinzu. –
@Antti ive hinzugefügt –