Results 1 to 2 of 2
  1. #1
    fred is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default problem with scanner class:incompatible types

    Why the following piece of code generate the error "incompatible types" on the next to the last line? It works if I use Object in place of String but String is supposed to work.
    Java Code:
    java.util.Scanner myinput = new java.util.Scanner(myInFile);
    while(myinput.hasNext())
    {
    String first = myinput.next();
    System.out.println(first);
    any ideas?

  2. #2
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    What version of Java ur using?
    It work just well on my computer, maybe some incompatibility problem with the class?:confused:
    Java Code:
    import java.util.*;
    import java.io.*;
    
    public class scanCheck
    {
    	public static void main(String[] args)throws IOException
    	{
    		File myInFile = new File("scanCheck.txt");
    		java.util.Scanner myinput = new java.util.Scanner(myInFile);
    		while(myinput.hasNext())
    		{
    			String first = myinput.next();
    			System.out.println(first);
    		}
    	}
    }

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2008, 08:09 AM
  2. Getting tokens using Scanner class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-05-2008, 09:11 AM
  3. Using Scanner class to read int value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:34 AM
  4. Scanner class
    By ajaymenon.k in forum Advanced Java
    Replies: 1
    Last Post: 11-26-2007, 07:01 AM
  5. JDK 5.0 Scanner Class
    By Sircedric88 in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •