Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O Issues  RSS feed

 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was writing a tester class for some automata representation classes I'd written. I was trying to take input and see if the system could take care of it accordingly. Unfortunately, I suck at I/O and, even though my class compiles, I keep getting run time errors.

Here are the methods that I use for all of the I/O stuff. I know its kind of gross looking, and I don't mean to ask people to be my error-inspectors. But if anyone can offer any suggestions as to where I/O might be giving me issues (the file is there, it locates it fine), that would be really awesome!

Here's the code!



The input for the file takes on the format:
stateName,isInitialNode,isFinalNode/token-nextNodePosition,token-nextNodePosition,....
For example: off,true,false/a-3,b-1,c-2

If you've gotten this far, thanks so much for your time and have a good day!
[ May 29, 2007: Message edited by: Vanessa Astle ]
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay to make this post seem less messy, I'm going to pinpoint the problem. I'm getting a NPE whenever I go to split the first line read from the file.
I initialized my String[] argsSet and I separated my Nodes and Transitions methods (you need all of the nodes to make any new transitions), so I'm a little lost.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm. Offhand I don't see the problem. Just to be safe, could you make sure you delete your existing .class files, then recompile? Then please show the stack trace, and whatever line number is cited at the top of the trace, let us know where that is in the file. (Because we can't look at your code and identify which line is line 42, for example.) Thanks.
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Prof. recommended that I use Scanner instead of BufferedReader so I changed my code around some. Now I'm getting an ArrayIndexOutofBoundsException instead of a NPE, but when I traced through the program I realized that the OBE could have easily been related to the NPE. Ihave the oddest feeling that the entire issue is being caused by my delimeter, but I don't really know much about delimeters to really know. Anyways, the exception stack trace is below.



java.lang.ArrayIndexOutOfBoundsException: 1
at NewAutomataTest.splitLines(NewAutomataTest.java:60)
at NewAutomataTest.main(NewAutomataTest.java:25)

Thanks so much!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16027
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are you sure that "//" is the right delimiter? Note that you don't need to escape slash / like you have to escape backslash \ by doubling it. Did you mean "/" instead of "//"?

The ArrayIndexOutOfBoundsException means that argsSet has only one element; argsSet[0], and argsSet[1] doesn't exist.
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wondered about that too, but I've tried splitting it with several different delimeters. None of them seem to work. I changed my class again, but the problem doesn't change.



Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at LetsTryThisAgain.readFile(LetsTryThisAgain.java:102) <=in bold
at LetsTryThisAgain.main(LetsTryThisAgain.java:11)

I'm still getting an out of bounds exception each time I run the program with the following input:

0,true,false/a-1,b-2
1,false,false/a-0,b-1
2,false,true/a-0,b-2

I am so frustrated with this program...
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, it was the new line feed that was giving me issues. I threw another split("\n") in there and it fixed everything right up.

Thanks though!
[ May 30, 2007: Message edited by: Vanessa Astle ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!