java.util.InputMismatchException

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

    #1

    java.util.InputMismatchException

    Code:
    Scanner sc = new Scanner("konta//"+NumerKonta+".txt");
    double sr_dost = sc.nextDouble();
    why i get the error here ?
    i wanna look for a double in a file
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    have you tried testing sc.hasNextDoubl e() to see if there is a valid token?

    also (although the API is not 100% clear (the examples at the top contradict what thwe methods explain, as I read it)), you may need to get rid of "rubbish" input (the examples suggest you don't need to , but I read the method to mean that it only tests the next token, and nothing more) eg:

    Code:
    while(sc.hasMoreTokens())
    {
      if(sc.hasNextDouble())
      {
        x = sc.nextDouble();
      }
      else
      {
        sc.next();
      }
    }
    }

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      thank u
      i used
      Code:
      while(sc.hasNext())
      {
        if(sc.hasNextDouble())
        {
      	  sr_dost = sc.nextDouble();
        }
        else
        {
          sc.next();
        }
      }
      and it works

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        Good stuff, that was lucky....

        Comment

        Working...