Hallo
Ich habe einen Fehler in meinem Programm und bekomme ihn nicht weg!
try {
in = new BufferedReader(new FileReader(eingeloggt + "_Vokabeln.voc"));
String zeile = null;
while ((zeile = in.readLine()) != null) {
list.add(zeile);
index = list.size();
mischen();
listIndex = (String) list.get(zufall);
splittArray = listIndex.split("\\|");
tfFrage.setText(splittArray[0].toString());
}
} catch (IOException e1) {
e1.printStackTrace();
}
btnUeberpruefen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(tfFrage.getText() == ""){
fragen();
}
else{
if(tfAntwort.getText() == "") JOptionPane.showMessageDialog(null, "Füllen Sie alle Felder aus");
else{
if(tfAntwort.getText().equals(splittArray[1].toString()){
JOptionPane.showMessageDialog(null, "Richtig");
list.remove(listIndex);
fragen();
}
else{
JOptionPane.showMessageDialog(null, "Falsch");
tfAntwort.setText("");
tfAntwort.repaint();
}
}
}
}
});```
Und hier noch die zwei Methoden :
public static void mischen(){
zufall = (int) (Math.random()*index);
}
public static void fragen(){
mischen();
tfFrage.setText("");
tfAntwort.setText("");
tfFrage.repaint();
tfAntwort.repaint();
BufferedReader in;
try {
in = new BufferedReader(new FileReader(eingeloggt + "_Vokabeln.voc"));
String zeile = null;
while ((zeile = in.readLine()) != null) {
list.add(zeile);
index = list.size();
mischen();
listIndex = (String) list.get(zufall);
splittArray = listIndex.split("\\|");
tfFrage.setText(splittArray[0].toString());
System.out.println(list);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
Mein Problem ist immer wenn die Textfelder Lehr sind und ich auf Überprüfen klicke bekomme ich einen Fehler:
Exception in thread “AWT-EventQueue-0” java.lang.ArrayIndexOutOfBoundsException: 1
at karteikasten.JFrame_1$6$1.actionPerformed(JFrame_1.java:407)
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.plaf.basic.BasicButtonListener.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$200(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$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.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$1.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)
Jetzt meine Frage an was kann das liegen dass ich immer eine Exception bekomme,
obwohl ich ja in einer if anweisung definiert habe, dass er wenn eines der beiden Felder lehr ist wieder eine neue Frage
machen soll, solange bis Die Textfelder beide einen Inhalt haben.
MFG
programmierer12