kyuubi426's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 7 (0.01 per day)
- Joined:
- 26-June 11
- Profile Views:
- 159
- Last Active:
Jun 28 2011 02:44 AM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- XBox
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Search Array Errpr
Posted 28 Jun 2011
-
In Topic: Reading CSV into 2D Array Using Tokenizer
Posted 28 Jun 2011
Thanks Crunch ! -
In Topic: Reading CSV into 2D Array Using Tokenizer
Posted 26 Jun 2011
Yes i understand and i have done that. Now The Code is:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package scannerreadfile; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import java.util.StringTokenizer; public class ScannerReadFile { String[][] line = new String[6][5]; public static void main(String[] args) throws IOException { String[][] line = new String[6][5]; Scanner inFile = new Scanner(new FileReader("data.csv")); String line1; int i =0; int j =0; while (inFile.hasNextLine()) { line1 = inFile.nextLine(); StringTokenizer st = new StringTokenizer(line1, ",", false); while (st.hasMoreTokens()) { line[i][j] = st.nextToken(); System.out.println(line[i][j]); j++; } i++; } ScannerReadFile operation= new ScannerReadFile(); Scanner scanner = new Scanner(System.in); System.out.println("Search for a birthday or surname, birthday= 'b'and surname= 's' "); String SOB= scanner.nextLine(); if(SOB.equals("s") || SOB.equals("S")){ operation.searchSurname(line); } if(SOB.equals("b") || SOB.equals("B")){ operation.searchBirthday(line); } } }
But it gives me the error:
Win
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
Henry
15
10 croyde
05/12/1995
at scannerreadfile.ScannerReadFile.main(ScannerReadFile.java:35)
Java Result: 1 -
In Topic: Reading CSV into 2D Array Using Tokenizer
Posted 26 Jun 2011
Crunch, on 26 June 2011 - 11:22 AM, said:Do you mean that for some reason the values of i and j are not being incremented ?Oh yeah i found your terrible error. Why use 4 loops ? What you have done with while loops is correct. you dont need any for loops here. Just two counters to keep track of i and j will make your program work
int i =0; int j =0; while (inFile.hasNextLine()) { line1 = inFile.nextLine(); StringTokenizer st = new StringTokenizer(line1, ",", false); j=0; while (st.hasMoreTokens()) { line[i][j] = st.nextToken(); System.out.println(line[i][j]); j++; } i++; }
Now it is saying there is an error on the line that holds this code.
line[i][j] = st.nextToken();
The exact error is
Win
Henry
15
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
10 croyde
at scannerreadfile.ScannerReadFile.main(ScannerReadFile.java:35)
Java Result: 1 -
In Topic: Reading CSV into 2D Array Using Tokenizer
Posted 26 Jun 2011
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Programming Languages:
- Java
Contact Information
- E-mail:
- Click here to e-mail me
Friends
kyuubi426 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
kyuubi426 has no profile comments yet. Why not say hello?