Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

was kann man bei falscher tastatureingabe tun?

Empfohlene Antworten

hi!

ich hab ein kleines problem......

also... ich will die PLZ durch eine tastatur einlesen

tastatur ist ein String (und muss ein string sein....(brauch ich für andre eingaben noch)

das was eingegeben wird (bei PLZ eine zahl) wird in einen string umgewandelt...

das klappt alles wunderbar...bloss wenn ich jetzt stat einer zahl ein buchstabe eingebe

bekomm ich ja eine fehlermeldung des kompilers.... ich will aber nicht das das passiert

ich will das die fehlermeldung "Fehler bei der Eingabe" angezeigt wird, und mann es erneutversuchen

kann. ich hab mich mit den problem heute den halben tag aussereinander gesetzt und hab keine lösung

gefunden auch nicht in der JAVA doku.

hat einer von euch vielleicht eine lösung für mich?

  

public  void Neu()

{

    BufferedReader eingabe = new BufferedReader(new InputStreamReader (System.in) );


    Person person = new Person();

    PersonAddress paddress = new PersonAddress();



    String tastatur;

    try

    {

        System.out.println("Bitte geben Sie die PLZ ein :");

        tastatur = eingabe.readLine();

        Integer test = new Integer(tastatur);

        int test1 = test.intValue();

        paddress.setPlz(test1);	

    }


    catch(IOException e)

    {

            System.out.print("Fehler bei der Eingabe!");

    }

}

hab auch das versucht:

  

            System.out.println("Bitte geben Sie die PLZ ein :");

            tastatur = eingabe.readLine();

            try 

            { 

            Integer.parseInt(tastatur); 

            }

            catch(NumberFormatException nfe) 

            {

            System.out.println("ERROR!!!");

            }

            int plz = Integer.parseInt(tastatur);

            paddress.setPlz(plz);

es klpt aber auch nicht!!

weil... fehlermeldung:

Bitte geben Sie die PLZ ein :

fe

ERROR!!!

Exception in thread "main" java.lang.NumberFormatException: fe

at java.lang.Integer.parseInt(Integer.java:414)

at java.lang.Integer.parseInt(Integer.java:463)

at HauptMenu.NeuKaufvertrag(HauptMenu.java:151)

at HauptMenu.NeuMenu(HauptMenu.java:1052)

at HauptMenu.display(HauptMenu.java:677)

at HauptMenu.<init>(HauptMenu.java:114)

at HauptMenu.main(HauptMenu.java:15)

Hi,

Du fängst den Fehler ab und wandelst dann trotzdem um (nach dem Catch), daher bekommst Du zwar den Error, aber dann eben auch die Exception.

Du mußt dafür sorgen, daß die Umwandlung nur dann stattfindet, wenn Du keine Exception hast.

Gruß Markus

meinst du das etfer so?

 

            System.out.println("Bitte geben Sie die PLZ ein :");


            tastatur = eingabe.readLine();


            try 


            { 


            Integer.parseInt(tastatur); 

            int plz = Integer.parseInt(tastatur);


            paddress.setPlz(plz);     


            }


            catch(NumberFormatException nfe) 


            {


            System.out.println("ERROR!!!");


            }


 

Hi,

ja so ungefähr hab ich mir das vorgestellt. Du mußt jetzt natürlich um das Ganze eine Schleife bauen, daß der User so lange was eingeben muß bis er keinen Fehler mehr macht.

Gruß Markus

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.