0

I'm trying to read data from a file and load into a two dimensional array and then print it to the screen.
but i keep receiving error code

Exception in thread "main" java.util.NoSuchElementException
    at java.util.StringTokenizer.nextToken(StringTokenizer.java:349)
    at test.main(test.java:14)

Here is my code below. Any advice would be great. I Feel like im missing something stupid and just need another pair of helpful eyes here. thanks

import java.io.*;
import java.util.*;

public class test{ 

    public static void main(String args[]) throws IOException{ 
        double [][] P= new double [5][3];

        BufferedReader Infile = new BufferedReader(new FileReader("P08RATE.DAT"));
        StringTokenizer Tokens;
        while (Infile.ready()){ 
            Tokens = new StringTokenizer(Infile.readLine());
            for (int k=0; k<P.length; k++)
                for (int j=0; j<P[k].length; j++)  
                    P[k][j] = Double.parseDouble(Tokens.nextToken());
        }
        Show(P);
    }

    /*-------------- Method: Show() ---------------*/
    private static void Show(double C[][]){ 
        int i, j;
        for (i=0; i < C.length; i++){ 
            for (j=0; j < C[i].length; j++)  
                System.out.print("  " + C[i][j]);
            System.out.println('\n');  
        }
    } //PrintArray

}
abronan
  • 3,309
  • 4
  • 29
  • 38

1 Answers1

0

It's not completely clear what you're trying to do without seeing the input file. But if it's strictly something like

double double double
double double double
double double double
double double double
double double double

You should have the line

Tokens = new StringTokenizer(Infile.readLine());

Inside of your first for loop.

Reinstate Monica Please
  • 11,123
  • 3
  • 27
  • 48
  • Yes! that was the problem. Thank you so much man. I was going absolutely nuts over it. Can't vote up yet. not enough rep. – user3084552 Dec 11 '13 at 16:28