# Java Programm für Prüfzahl Berechnung eines Persnalausweises bzw. Prüfung auf Richtigkeit



## bbstrike (2. Jun 2015)

Hallo,
Ich muss aktuell ein Java-Projekt für die schule realisieren und habe nun auch schon den Großteil gemacht leider wirft Java bei meinem Projekt immer einen Fehler aus. Der da wäre :


```
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:592)
    at java.lang.Integer.parseInt(Integer.java:615)
    at personalausweis.jButton1_ActionPerformed(personalausweis.java:324)
    at personalausweis$1.actionPerformed(personalausweis.java:222)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
```

Ich habe keine Ahnung woran dies liegen könnte bitte um Hilfe
hier der Quelltext:

```
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;








public class personalausweis extends JFrame {
  // Anfang Attribute
  private JLabel jLabel1 = new JLabel();
  private JTextField jTextField1 = new JTextField();
  private JLabel jLabel2 = new JLabel();
  private JTextField jTextField2 = new JTextField();
  private JLabel jLabel3 = new JLabel();
  private JNumberField jNumberField1 = new JNumberField();
  private JNumberField jNumberField2 = new JNumberField();
  private JNumberField jNumberField3 = new JNumberField();
  private JNumberField jNumberField4 = new JNumberField();
  private JNumberField jNumberField5 = new JNumberField();
  private JNumberField jNumberField6 = new JNumberField();
  private JNumberField jNumberField7 = new JNumberField();
  private JNumberField jNumberField8 = new JNumberField();
  private JNumberField jNumberField9 = new JNumberField();
  private JNumberField jNumberField10 = new JNumberField();
  private JTextField jTextField4 = new JTextField();
  private JLabel jLabel4 = new JLabel();
  private JLabel jLabel5 = new JLabel();
  private JNumberField jNumberField11 = new JNumberField();
  private JNumberField jNumberField12 = new JNumberField();
  private JNumberField jNumberField13 = new JNumberField();
  private JNumberField jNumberField14 = new JNumberField();
  private JNumberField jNumberField15 = new JNumberField();
  private JNumberField jNumberField16 = new JNumberField();
  private JNumberField jNumberField17 = new JNumberField();
  private JLabel jLabel6 = new JLabel();
  private JNumberField jNumberField18 = new JNumberField();
  private JNumberField jNumberField19 = new JNumberField();
  private JNumberField jNumberField20 = new JNumberField();
  private JNumberField jNumberField21 = new JNumberField();
  private JNumberField jNumberField22 = new JNumberField();
  private JNumberField jNumberField23 = new JNumberField();
  private JNumberField jNumberField24 = new JNumberField();
  private JLabel jLabel7 = new JLabel();
  private JNumberField jNumberField25 = new JNumberField();
  private JLabel jLabel8 = new JLabel();
  private JButton jButton1 = new JButton();
  private JLabel jLabel9 = new JLabel();
  
    
    
    String nachname;
    String vorname;
    int zahl1;
    int zahl2; 
    int zahl3;
    int zahl4;
    int zahl5;
    int zahl6;
    int zahl7;
    int zahl8;
    int zahl9;
    int zahl10;
    int zahl11;
    int zahl12; 
    int zahl13;
    int zahl14;
    int zahl15;
    int zahl16;
    int zahl17;
    int zahl18;
    int zahl19;
    int zahl20;
    int zahl21;
    int zahl22;
    int zahl23;
    int zahl24;
    int zahl25; 
   
  
  
  
  
  // Ende Attribute
  
  public personalausweis(String title) { 
    // Frame-Initialisierung
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 800; 
    int frameHeight = 784;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);
    // Anfang Komponenten
    
    jLabel1.setBounds(74, 88, 30, 25);
    jLabel1.setText("<<");
    cp.add(jLabel1);
    jTextField1.setBounds(96, 88, 94, 25);
    
    cp.add(jTextField1);
    jLabel2.setBounds(192, 88, 30, 25);
    jLabel2.setText("<<");
    cp.add(jLabel2);
    jTextField2.setBounds(216, 88, 94, 25);
    cp.add(jTextField2);
    jLabel3.setBounds(312, 88, 94, 25);
    jLabel3.setText("<<<<<<<<<<<<<");
    cp.add(jLabel3);
    jNumberField1.setBounds(48, 120, 19, 25);
    jNumberField1.setText("");
    cp.add(jNumberField1);
    jNumberField2.setBounds(72, 120, 19, 25);
    jNumberField2.setText("");
    cp.add(jNumberField2);
    jNumberField3.setBounds(96, 120, 19, 25);
    jNumberField3.setText("");
    cp.add(jNumberField3);
    jNumberField4.setBounds(120, 120, 19, 25);
    jNumberField4.setText("");
    cp.add(jNumberField4);
    jNumberField5.setBounds(144, 120, 19, 25);
    jNumberField5.setText("");
    cp.add(jNumberField5);
    jNumberField6.setBounds(168, 120, 19, 25);
    jNumberField6.setText("");
    cp.add(jNumberField6);
    jNumberField7.setBounds(192, 120, 19, 25);
    jNumberField7.setText("");
    cp.add(jNumberField7);
    jNumberField8.setBounds(216, 120, 19, 25);
    jNumberField8.setText("");
    cp.add(jNumberField8);
    jNumberField9.setBounds(240, 120, 19, 25);
    jNumberField9.setText("");
    cp.add(jNumberField9);
    jNumberField10.setBounds(264, 120, 19, 25);
    jNumberField10.setText("");
    cp.add(jNumberField10);
    jTextField4.setBounds(288, 120, 30, 25);
    cp.add(jTextField4);
    jLabel4.setBounds(48, 88, 30, 25);
    jLabel4.setText("IDD");
    cp.add(jLabel4);
    jLabel5.setBounds(320, 120, 14, 25);
    jLabel5.setText("<<");
    cp.add(jLabel5);
    jNumberField11.setBounds(336, 120, 19, 25);
    jNumberField11.setText("");
    cp.add(jNumberField11);
    jNumberField12.setBounds(360, 120, 19, 25);
    jNumberField12.setText("");
    cp.add(jNumberField12);
    jNumberField13.setBounds(384, 120, 19, 25);
    jNumberField13.setText("");
    cp.add(jNumberField13);
    jNumberField14.setBounds(408, 120, 19, 25);
    jNumberField14.setText("");
    cp.add(jNumberField14);
    jNumberField15.setBounds(432, 120, 19, 25);
    jNumberField15.setText("");
    cp.add(jNumberField15);
    jNumberField16.setBounds(456, 120, 19, 25);
    jNumberField16.setText("");
    cp.add(jNumberField16);
    jNumberField17.setBounds(480, 120, 19, 25);
    jNumberField17.setText("");
    cp.add(jNumberField17);
    jLabel6.setBounds(504, 120, 14, 25);
    jLabel6.setText("<");
    cp.add(jLabel6);
    jNumberField18.setBounds(520, 120, 19, 25);
    jNumberField18.setText("");
    cp.add(jNumberField18);
    jNumberField19.setBounds(544, 120, 19, 25);
    jNumberField19.setText("");
    cp.add(jNumberField19);
    jNumberField20.setBounds(568, 120, 19, 25);
    jNumberField20.setText("");
    cp.add(jNumberField20);
    jNumberField21.setBounds(592, 120, 19, 25);
    jNumberField21.setText("");
    cp.add(jNumberField21);
    jNumberField22.setBounds(616, 120, 19, 25);
    jNumberField22.setText("");
    cp.add(jNumberField22);
    jNumberField23.setBounds(640, 120, 19, 25);
    jNumberField23.setText("");
    cp.add(jNumberField23);
    jNumberField24.setBounds(664, 120, 19, 25);
    jNumberField24.setText("");
    cp.add(jNumberField24);
    jLabel7.setBounds(688, 120, 54, 25);
    jLabel7.setText("<<<<<<<");
    cp.add(jLabel7);
    jNumberField25.setBounds(738, 120, 19, 25);
    jNumberField25.setText("");
    cp.add(jNumberField25);
    jLabel8.setBounds(88, 336, 627, 425);
    jLabel8.setIcon(new ImageIcon("Perso.PNG"));
    jLabel8.setText("Perso.png");
    cp.add(jLabel8);
    
                    
    jButton1.setBounds(328, 200, 171, 65);
    jButton1.setText("Personalausweis Prüfen");
    jButton1.setMargin(new Insets(2, 2, 2, 2));
    jButton1.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        jButton1_ActionPerformed(evt);
      }
    });
    cp.add(jButton1);
    jLabel9.setBounds(216, 16, 403, 41);
    jLabel9.setText("Geben sie die Prüfziffern ihres Personalasweises ein. (Siehe unten)");
    cp.add(jLabel9);
    setTitle("IDC - Identification Check");
    
    
    
    
    
    
    // Ende Komponenten
    
    setVisible(true);
  }
  
  // Anfang Methoden
  public void jButton1_ActionPerformed(ActionEvent evt) {
    
    
    nachname = jTextField1.getSelectedText();
    vorname = jTextField2.getSelectedText();
    
    zahl1 = jNumberField1.getInt();
    zahl2 = jNumberField2.getInt();
    zahl3 = jNumberField3.getInt();
    zahl4 = jNumberField4.getInt();
    zahl5 = jNumberField5.getInt();
    zahl6 = jNumberField6.getInt();
    zahl7 = jNumberField7.getInt();
    zahl8 = jNumberField8.getInt();
    zahl9 = jNumberField9.getInt();
    zahl10 = jNumberField10.getInt();
    String land = jTextField4.getSelectedText();
    zahl11 = jNumberField11.getInt();
    zahl12 = jNumberField12.getInt();
    zahl13 = jNumberField13.getInt();
    zahl14 = jNumberField14.getInt();
    zahl15 = jNumberField15.getInt();
    zahl16 = jNumberField16.getInt();
    zahl17 = jNumberField17.getInt();
    zahl18 = jNumberField18.getInt();
    zahl19 = jNumberField19.getInt();
    zahl20 = jNumberField20.getInt();
    zahl21 = jNumberField21.getInt();
    zahl22 = jNumberField22.getInt();
    zahl23 = jNumberField23.getInt();
    zahl24 = jNumberField24.getInt();
    zahl25 = jNumberField25.getInt();
            
    
    zahl1 = zahl1 * 7;
    zahl2 = zahl2 * 3; 
    zahl3 = zahl3 * 1;
    zahl4 = zahl4 * 7;
    zahl5 = zahl5 * 3; 
    zahl6 = zahl6 * 1;
    zahl7 = zahl7 * 7;
    zahl8 = zahl8 * 3;
    zahl9 = zahl9 * 1;
    zahl11 = zahl11 * 3;
    zahl12 = zahl12 * 1;
    zahl13 = zahl13 * 7;
    zahl14 = zahl14 * 3;
    zahl15 = zahl15 * 1;
    zahl16 = zahl16 * 7;
    zahl18 = zahl18 * 1;
    zahl19 = zahl19 * 7;
    zahl20 = zahl20 * 3;
    zahl21 = zahl21 * 1;
    zahl22 = zahl22 * 7;
    zahl23 = zahl23 * 3;
    
    
    //zahl1
    String s1 = String.valueOf(zahl1);    
    int index1 = s1.length();                
    int länge1 = index1-1;                  
    s1 = s1.substring(länge1, index1);
    int z1 = Integer.parseInt(s1.toString()); 
    


    //zahl2
    String s2 = String.valueOf(zahl2);    
    int index2 = s2.length();                
    int länge2 = index1-1;                  
    s2 = s2.substring(länge2, index2);
    int z2 = Integer.parseInt(s2.toString());
    
    
    //zahl3
    String s3 = String.valueOf(zahl3);    
    int index3 = s3.length();                
    int länge3 = index1-1;                  
    s3 = s3.substring(länge3, index3);
    int z3 = Integer.parseInt(s3.toString());
    
    
    
    //zahl4
    String s4 = String.valueOf(zahl4);    
    int index4 = s4.length();                
    int länge4 = index1-1;                  
    s4 = s4.substring(länge4, index4);
    int z4 = Integer.parseInt(s4.toString());
    
    //zahl5
    String s5 = String.valueOf(zahl5);    
    int index5 = s5.length();                
    int länge5 = index1-1;                  
    s5 = s5.substring(länge5, index5);
    int z5 = Integer.parseInt(s5.toString());
    
    //zahl6
    String s6 = String.valueOf(zahl6);    
    int index6 = s6.length();                
    int länge6 = index1-1;                  
    s6 = s6.substring(länge6, index6);    
    int z6 = Integer.parseInt(s6.toString());
    
    //zahl7
    String s7 = String.valueOf(zahl7);    
    int index7 = s7.length();                
    int länge7 = index1-1;                  
    s7 = s7.substring(länge7, index7);
    int z7 = Integer.parseInt(s7.toString());
    
    //zahl8
    String s8 = String.valueOf(zahl8);    
    int index8 = s8.length();                
    int länge8 = index1-1;                  
    s8 = s8.substring(länge8, index8);
    int z8 = Integer.parseInt(s8.toString());
    
    //zahl9
    String s9 = String.valueOf(zahl9);    
    int index9 = s9.length();                
    int länge9 = index1-1;                  
    s9 = s9.substring(länge9, index9);
    int z9 = Integer.parseInt(s9.toString());
    
    //zahl11
    String s11 = String.valueOf(zahl11);    
    int index11 = s11.length();                
    int länge11 = index1-1;                  
    s11 = s11.substring(länge11, index11);
    int z11 = Integer.parseInt(s11.toString());
    
    //zahl12
    String s12 = String.valueOf(zahl12);    
    int index12 = s12.length();                
    int länge12 = index1-1;                  
    s12 = s12.substring(länge12, index12);
    int z12 = Integer.parseInt(s12.toString());
 
    //zahl13
    String s13 = String.valueOf(zahl13);    
    int index13 = s13.length();                
    int länge13 = index1-1;                  
    s13 = s13.substring(länge13, index13);
    int z13 = Integer.parseInt(s13.toString());
    
    //zahl14
    String s14 = String.valueOf(zahl14);    
    int index14 = s14.length();                
    int länge14 = index1-1;                  
    s14 = s14.substring(länge14, index14);
    int z14 = Integer.parseInt(s14.toString());
    
    //zahl15
    String s15 = String.valueOf(zahl15);    
    int index15 = s15.length();                
    int länge15 = index1-1;                  
    s15 = s15.substring(länge15, index15);
    int z15 = Integer.parseInt(s15.toString());
    
    //zahl16
    String s16 = String.valueOf(zahl16);    
    int index16 = s16.length();                
    int länge16 = index1-1;                  
    s16 = s16.substring(länge16, index16);
    int z16 = Integer.parseInt(s16.toString());
    
    //zahl18
    String s18 = String.valueOf(zahl18);    
    int index18 = s18.length();                
    int länge18 = index1-1;                  
    s18 = s18.substring(länge18, index18);
    int z18 = Integer.parseInt(s18.toString());
    
    //zahl19
    String s19 = String.valueOf(zahl19);    
    int index19 = s19.length();                
    int länge19 = index1-1;                  
    s19 = s19.substring(länge19, index19);
    int z19 = Integer.parseInt(s19.toString()); 
    
    //zahl20
    String s20 = String.valueOf(zahl20);    
    int index20 = s20.length();                
    int länge20 = index1-1;                  
    s20 = s20.substring(länge20, index20);
    int z20 = Integer.parseInt(s20.toString());
    
    //zahl21
    String s21 = String.valueOf(zahl21);    
    int index21 = s21.length();                
    int länge21 = index1-1;                  
    s21 = s21.substring(länge21, index21);
    int z21 = Integer.parseInt(s21.toString());
    
    //zahl22
    String s22 = String.valueOf(zahl22);    
    int index22 = s22.length();                
    int länge22 = index1-1;                  
    s22 = s22.substring(länge22, index22);
    int z22 = Integer.parseInt(s22.toString());
    
    //zahl23
    String s23 = String.valueOf(zahl23);    
    int index23 = s23.length();                
    int länge23 = index1-1;                  
    s23 = s23.substring(länge23, index23);
    int z23 = Integer.parseInt(s23.toString());
    
    
    
    //Prüfziffer1(zahl10)
    int pruef1;
    pruef1 =  z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9; 
    String p1 = String.valueOf(pruef1);    
    int indexp1 = p1.length();                
    int längep1 = index1-1;                  
    p1 = p1.substring(längep1, indexp1);
    int pu1 = Integer.parseInt(p1.toString());
    
    //Prüfziffer2 (zahl17)
    int pruef2;
    pruef2 =  z11 + z12 + z13 + z14 + z15 + z16;
    String p2 = String.valueOf(pruef2);    
    int indexp2 = p2.length();                
    int längep2 = index1-1;                  
    p2 = p2.substring(längep2, indexp2);
    int pu2 = Integer.parseInt(p2.toString());
    
    //Prüfziffer3 (zahl124)
    int pruef3;
    pruef3 =  z18 + z19 + z20 + z21 + z22 + z23;
    String p3 = String.valueOf(pruef3);    
    int indexp3 = p3.length();                
    int längep3 = index1-1;                  
    p3 = p3.substring(längep3, indexp3);
    int pu3 = Integer.parseInt(p3.toString());
    
    //Prüfziffer4 (zahl25)
    int pruef4;
    pruef4 =  pruef1 + pruef2 + pruef3 + pu1 * 7 + pu2 * 3 + pu3 * 1;
    String p4 = String.valueOf(pruef4);    
    int indexp4 = p4.length();                
    int längep4 = index1-1;                  
    p4 = p4.substring(längep4, indexp4);
    int pu4 = Integer.parseInt(p4.toString());
    
    System.out.println("5");
    
    if(zahl10 == pu1 && zahl17 == pu2 && zahl24 == pu3 && zahl25 == pu4){
       System.out.println("Right");
       
      
    }
    else{
       System.out.println("false");
       
  }
    
     }
    
    
    // Ende Methoden
  
  public static void main(String[] args) {
    new personalausweis("IDC - Identification Check");
    
  
      
    }
  }
```


Vielen Dank schon einmal


----------



## Dompteur (2. Jun 2015)

Beginnend mit Zeile 311 hast du ein systematisches Problem:

```
int länge2 = index1-1;
```
Du berechnest also alle längeX-Werte auf Basis von index*1*.

Wenn du schon keine Arrays verwendest, solltest du wenigstens die Behandlung der einzelnen Ziffern in eine eigene Methode verlagern. Damit verringerst du die Wahrscheinlichkeit solcher Copy-Paste-Fehler.
Außer du wirst nach Zeilen bezahlt. ;-)


----------



## VfL_Freak (2. Jun 2015)

Moin,

die Exception fliegt hier:
*at personalausweis.jButton1_ActionPerformed(personalausweis.java:324*

Ist im von Dir geposteten Code allerdings eine leere Zeile .....

Gruß Klaus


----------

