Einzelnen Beitrag anzeigen
Alt 04.01.2004, 22:43   #27
poison
Jr. Member
 
Registriert seit: 01.04.2001
Alter: 41
Beiträge: 59


Standard

danke für deine hilfe!

also das mit dem einlesen ist nun kein problem mehr -> dafür kann ich das ganze nicht zu einer methode mit rückgabewert machen (was in diesem fall wohl sinnvoll wäre)

mein rückgabewert sollte der Punkt mit x- und y-Koordinate sein

was ist daran falsch?

Code:
    private static Point2D.Float einlesen()
    {
        float xKoord, yKoord;
        String input = ""; // dieser String enthält die Eingabe
        int counter = 0; // zum Zählen der Koordinatenpaare
        
         do
        {
            input = readWord();
            
            int index1 = input.indexOf('(');
            int index2 = input.indexOf(')');
            
            if ( (index1 != -1) && (index2 > index1))
            {
                String teil = input.substring(index1+1, index2);
                
                try
                {
                    xKoord=Float.parseFloat(teil.substring(0, teil.indexOf(',')));
                    yKoord=Float.parseFloat(teil.substring(teil.indexOf(',')+1, teil.length()));
                    Point2D.Float punkt = new Point2D.Float(xKoord, yKoord);
                
                    if ( (xKoord < -100) || (xKoord > 100) || (yKoord < -100) || (yKoord > 100) )
                    {
                        println ("FALSCHE EINGABE");
                    }
                    
                    counter++;
                    
                    if ( (counter < 3) || (counter > 15) )
                    {
                        println ("FALSCHE EINGABE");
                    }
                }
            
                catch (NumberFormatException e)
                {
                    throw new IllegalArgumentException("FALSCHE EINGABE");
                }
            }
         } while (!(input.endsWith("=")));
        
        return Point2D.Float;
    }
die fehlermeldung:
Konvneck.java [67:1] variable xKoord might not have been initialized
return new Point2D.Float(xKoord,yKoord);
^
Konvneck.java [67:1] variable yKoord might not have been initialized
return new Point2D.Float(xKoord,yKoord);
^
2 errors
Errors compiling Konvneck.

ich verstehe schon, dass er die variablen nicht kennt -> sie existieren ja nur im try-catch-block
nur weiß ich nicht wie ich das beheben könnte

mfg poison
poison ist offline   Mit Zitat antworten