Results 1 to 2 of 2
- 05-12-2012, 07:00 AM #1
Member
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
input file into array with different parameters
This is doing my head in.
I have 2 different formats in a text file that i need to enter into an array
I am using
One of the constructors has 3 args. The other has 4, so I'm using an if statement to guide the program into which constructor to use.Java Code:String line = file.nextLine(); String[] output = new String[4]; output = line.split(":");
I continue to get a ArrayIndexOutOfBoundsException and I cannot figure out what to do.Java Code:if (output[3] != null) { FirstClassTicket f = new FirstClassTicket(Integer.parseInt(output[0]), output[1], Integer.parseInt(output[2]), output[3].charAt(0)); System.out.printf("%d %s %d %s\n", f.getSeat(), f.getName(), f.getDuration(), f.getWaiter()); tickets.add(f); } else { TrainTicket t = new TrainTicket(Integer.parseInt(output[0]), output[1], Integer.parseInt(output[2])); System.out.printf("%d %s %d\n", t.getSeat(), t.getName(), t.getDuration()); tickets.add(t); }Last edited by Pulse8; 05-13-2012 at 02:16 AM. Reason: reformat
- 05-12-2012, 08:18 AM #2
Re: input file into array with different parameters
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Reading input from a .txt file and then putting it into a array
By BetaDave1877 in forum New To JavaReplies: 2Last Post: 04-16-2012, 12:56 AM -
taking input from a txt file and creating an array from tha taken integers
By romero4742 in forum New To JavaReplies: 4Last Post: 03-15-2012, 07:55 PM -
read input file into array
By randoms:) in forum New To JavaReplies: 3Last Post: 04-23-2011, 08:52 AM -
file input: array of integers
By hannes in forum New To JavaReplies: 8Last Post: 01-27-2010, 03:44 PM -
Reading input file into an array
By littlefire in forum New To JavaReplies: 6Last Post: 10-18-2008, 11:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks