|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Help with filereader
Hello I am using RoboRealm to find the hotzone, and write its x position on a file (variables). I am using the filreader to read the variables to my code(please tell my how to use spoilers) and am getting a mysterious error that only appears sometimes.
---------------------------------CODE------------------------ package recognitiotion; import java.io.FileReader; import java.io.IOException; /** * * @author rc10545 */ public class getCog_X { int[] Cog_X = new int[9999]; //Creates the Cog_X array int cogi = 0; // controls Cog_X array public void cog() throws IOException { FileReader fr = new FileReader("c:/cygwin64/home/rc10545/variables"); char[] a = new char[9999999]; int i; fr.read(a); //updates text String y = new String(a); //Converts the char to one big string String tokens[] = y.split("\r\n"); //splits the string down on every line break i = tokens.length; //Gets a variable for how long the tokens array is Integer convert = Integer.valueOf(tokens[i - 2]); // converts tokens into the convert int Error is here between these two lines ![]() Cog_X[cogi] = convert; // changes the convert variable into an array // goes to the next Cog_X array item\ }//method cog public void positioner(int Cogx) { System.out.println(Cogx); int remember = 0; //remembers wether it hass does the initial movement if (remember == 0 && Cogx > 320) { //goright for [five] seconds remember++; } else if (remember == 0) { //goleft for [less] seconds remember++; }//does initial movement to bit right of the center of hotzone if (remember == 2 && Cogx > 300 && Cogx < 330) { System.out.println(Cogx); } else if (remember == 1) { remember++; //makes sure it does not shoot while moving }//shooter cogi++; }//method positioner public void runner() throws IOException { int Cogx; //Positioner's Cog_X[cogi] while (true) { cog(); Cogx = Cog_X[cogi]; positioner(Cogx); }//infinite while loop }//method main public static void main(String args[]) throws IOException { (new getCog_X()).runner(); } }//class ------------------------------------Code--------------------------------- --------------------------------ERROR------------------------------------ run: Exception in thread "main" java.lang.NumberFormatException: For input string: "5 " at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.valueOf(Integer.java:582) at recognitiotion.getCog_X.cog(getCog_X.java:32) at recognitiotion.getCog_X.runner(getCog_X.java:73) at recognitiotion.getCog_X.main(getCog_X.java:84) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds) --------------------------------ERROR------------------------------------ |
|
#2
|
|||||
|
|||||
|
Re: Help with filereader
Code:
Integer convert = Integer.valueOf(tokens[i - 2]); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|