Exception in thread "main" java.util.NoSuchElementException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • olga nekrasov

    Exception in thread "main" java.util.NoSuchElementException

    hello
    I have a problem with my code...
    here's the complete lines of errors:

    Code:
    Exception in thread "main" java.util.NoSuchElementException
    	at java.util.Scanner.throwFor(Unknown Source)
    	at java.util.Scanner.next(Unknown Source)
    	at java.util.Scanner.nextInt(Unknown Source)
    	at java.util.Scanner.nextInt(Unknown Source)
    	at hakbaz.Short.reader(Short.java:45)
    	at hakbaz.Main.main(Main.java:11)
    may be some one know what it means or what can I do to fix it..


    Code:
    package hakbaz;
    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Scanner;
    
    public class Short {
    	public static int [][]road;
    	public static int x;
    	public static int n;
    	public static int t;
    
    	public void reader() {
    		Scanner sc;
    		String str;
    		int i;
    		File file = new File("data.TXT");
    	    FileInputStream fis = null;
    	    BufferedInputStream bis = null;
    	    DataInputStream dis = null;
    	    try {
    	      fis = new FileInputStream(file);
    	      bis = new BufferedInputStream(fis);
    	      dis = new DataInputStream(bis);
    	      str = dis.readLine();
    	      sc = new Scanner(str);
    	      n=sc.nextInt();
    	      str = dis.readLine();
    	      sc = new Scanner(str);
    	      x=sc.nextInt();
    	      str = dis.readLine();
    	      sc = new Scanner(str);
    	      t=sc.nextInt();
    	      dis.readLine();
    	      i=0;
    	      int col=(2*x)+3;
    	      road = new int[n][col];
    	      while (dis.available() != 0) {
    	    	str = dis.readLine();
    	        sc = new Scanner(str);
    	        for (int j=0; j<col; j++)
    	        	road[i][j]=sc.nextInt();
    	        i++;
    	      }
    	      fis.close();
    	      bis.close();
    	      dis.close();
    	    } catch (FileNotFoundException e) {
    	      e.printStackTrace();
    	    } catch (IOException e) {
    	      e.printStackTrace();
    	    }
    		
    	}
    	
    
    }
    
    package hakbaz;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Short way= new Short();
    		way.reader();
    		System.out.println(Short.n+" "+Short.road[0][2]);
    
    	}
    
    }
    Last edited by Dormilich; Nov 23 '10, 11:20 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Sean Pedersen
    New Member
    • Dec 2010
    • 30

    #2
    Try System.in for your Scanner, you have it streaming from a string.

    Comment

    Working...