variable prob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    variable prob

    whu eclipse highlights the return balans as an error not declared variable
    although it's declared
    double balans = Double.valueOf( dane[dane.length].trim()).double Value();


    Code:
    private double get_sr_dost(String numer_konta)
    			{     
    	
    	
    	try{
    	    
    	    
    	    BufferedReader in = new BufferedReader(new FileReader("konta//"+numer_konta+".txt"));
    		       
    	    
    	    
    	    String wczytane_dane="";
    	    String line = in.readLine();
    	
    	  
    	  while((line = in.readLine()) != null)   {   
    		  wczytane_dane+=line;
    	    	line = in.readLine();
    	    	wczytane_dane+=":";
    	  }
    	  
    	 
    	  
    String[] dane=wczytane_dane.split(":");	    
    double  balans = Double.valueOf(dane[dane.length].trim()).doubleValue();
    in.close();
    	  }catch (FileNotFoundException e) {
    		    System.err.println("Nie ma takiego konta(File not found!)");
    	  }catch (IOException e) {
    	          System.err.println(e);
    	  } catch (NumberFormatException e) {
    	         System.out.println("NumberFormatException: " + e.getMessage());    
    	  }catch (Exception ex)  {
          ex.printStackTrace();  }
    	 
    	
    	return balans;
    }
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #2
    okey i fixed it

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by oll3i
      okey i fixed it
      Would you mind posting yoru solution in case someone else has the same trouble?

      (I'm guessing it was to do with dane[dane.length] , but I'd like to know for sure!)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by oll3i
        whu eclipse highlights the return balans as an error not declared variable
        although it's declared
        double balans = Double.valueOf( dane[dane.length].trim()).double Value();


        Code:
        private double get_sr_dost(String numer_konta)
        			{ 
         
         
        	try{
         
         
        	 BufferedReader in = new BufferedReader(new FileReader("konta//"+numer_konta+".txt"));
         
         
         
        	 String wczytane_dane="";
        	 String line = in.readLine();
         
         
        	 while((line = in.readLine()) != null) { 
        		 wczytane_dane+=line;
        		 line = in.readLine();
        		 wczytane_dane+=":";
        	 }
         
         
         
        String[] dane=wczytane_dane.split(":");	 
        double balans = Double.valueOf(dane[dane.length].trim()).doubleValue();
        in.close();
        	 }catch (FileNotFoundException e) {
        		 System.err.println("Nie ma takiego konta(File not found!)");
        	 }catch (IOException e) {
        	 System.err.println(e);
        	 } catch (NumberFormatException e) {
        	 System.out.println("NumberFormatException: " + e.getMessage()); 
        	 }catch (Exception ex) {
        ex.printStackTrace(); }
         
         
        	return balans;
        }
        You declared it inside the try block and tried to return it outside the try block where it was now out of scope.

        Comment

        Working...