The program is to write the coordinates generated by the program to another file, then read the file. My program compiles but when i run it i get this error
java.lang.NumberFormatException: For input string: "[29.42051539113255, -1.3622522059837383], "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at J4.readfile(J4_2_MultiDimensionalArray7.java:52)
at J4.main(J4.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
>
What does this error mean? How can I fix it? Thanks!
CODE:
import java.io.*;
import java.util.Arrays;
public class J4
{
public static void main (String [] args) throws IOException
{
int numpoints = 100, dimension = 2, length = 100;
double [] lengthscale = new double [dimension];
double [][] locations = new double [numpoints][dimension];
PrintWriter fileOut = new PrintWriter (new FileWriter ("arrayNumPoints.txt"));
writefile(lengthscale, locations, dimension, numpoints, length);
for(int m=0; m <length; m++){
fileOut.println(Arrays.toString(locations[m]) + ", ");
}
fileOut.close ();
readfile();
}
public static void writefile(double lengthscale[], double locations[][], int dimension, int numpoints, int length)throws IOException
{
for (int a = 0; a < dimension; a++) {
lengthscale[a] = length;
}
for (int x=0; x < numpoints; x++){
for (int y=0; y < dimension; y++){
locations [x][y]= (2 * Math.random() - 1) * lengthscale[y];
}
}
}
public static void readfile()throws IOException
{
BufferedReader readFile = new BufferedReader (new FileReader ("arrayNumPoints.txt"));
int readarray [] = new int [100];
for (int counter=0; counter < 100; counter++){
readarray[counter] = Integer.parseInt (readFile.readLine ());
}
}
}