Having a simple issue with the Scanner class...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Having a simple issue with the Scanner class...

  1. #1
    Join Date
    Oct 2005
    Posts
    5

    Having a simple issue with the Scanner class...

    Hi, doing a homework assignment in a intro to Java class, some reason the scanner class is giving me problems, I am typing the code as it appears in the text and getting the following error output. I am using vi to do the coding.
    thanks for any help in advance.


    Temperature.java:1: cannot resolve symbol
    symbol : class Scanner
    location: package util
    import java.util.Scanner;
    ^
    Temperature.java:13: cannot resolve symbol
    symbol : class Scanner
    location: class Temperature
    Scanner scan = new Scanner (System.in);

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I beleive the Scanner class requires java 1.5, have you got that installed properly ?
    eschew obfuscation

  3. #3
    Join Date
    Oct 2005
    Posts
    5
    what is the bash command to view java version? All i am finding is java 1.4

  4. #4
    Join Date
    Oct 2005
    Posts
    5
    java version "1.4.2_09"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-232)
    Java HotSpot(TM) Client VM (build 1.4.2-54, mixed mode)


    I cant find no 1.5... (ugh)

  5. #5
    Join Date
    Oct 2005
    Posts
    5
    I guess I can not do on my Mac box, it will most likely work on my linux, ok, thanks though.

  6. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Make your own Scanner class

    Code:
    public class MyScanner {
      static BufferedReader console=new BufferedReader(new   InputStreamReader(System.in));
    
      // use it like
      public int getUserInt() {
        while (true) {
          System.out.print("Please enter an integer value");
          String s=console.readLine().trim();
          try {
            int iVal=Integer.parseInt(s);
            return iVal;
          } catch (NumberFormatException ne) {
             System.err.println("["+s+"] is not not an integer);         
          } catch (IOException ioe) {
            System.err.println("An error occured: "+ioe.getMessage());
          }
          System.out.println("Please reenter");
        }
      }
    }
    There is nothing you can do in 1.5 java that cannot be coded up in
    1.4 java.
    Last edited by sjalle; 10-31-2005 at 03:18 AM. Reason: I need new glasses
    eschew obfuscation

Similar Threads

  1. Vector and StreamTokenizer problem
    By dagma20 in forum Java
    Replies: 5
    Last Post: 02-23-2005, 01:13 AM
  2. class vector<?>
    By pseudo in forum C++
    Replies: 3
    Last Post: 02-14-2005, 07:48 AM
  3. Set Scope of Class Members Dynamically
    By Ian Diaz in forum .NET
    Replies: 1
    Last Post: 08-31-2002, 12:50 PM
  4. Replies: 205
    Last Post: 09-26-2001, 02:37 PM
  5. How To Do It - Shared Class Variables Part II
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 04-26-2001, 03:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center