Go to Post You have to start at the bottom to get to the top, usually. - Kyle [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2014, 16:56
TheTurtleofDoom TheTurtleofDoom is offline
Registered User
FRC #2988
 
Join Date: Feb 2014
Location: Virginia
Posts: 4
TheTurtleofDoom is an unknown quantity at this point
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------------------------------------
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2014, 17:05
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Help with filereader

Code:
Integer convert = Integer.valueOf(tokens[i - 2]);
What happens when y contains something that isn't parseable as an integer? For example, you might only read a partial message and end up with a null string for one of the tokens, or is less than 2 tokens long.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi