Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenize r.java:332)
at CsvTest.readFile(CsvTest.java:26)
at Trial.main(Trial.java:24)
I have no idea what to change here because I don't know what is wrong..please help me out...
Expand|Select|Wrap|Line Numbers
- import java.io.*;
- import java.util.*;
- import javax.swing.*;
- public class Trial {
- public static void main(String [] args) throws IOException {
- BufferedReader s = null;
- FileOutputStream out;
- PrintStream p;
- String CDtitle[] = new String[1000],
- category[] = new String [1000],
- container[] = new String [1000],
- location[] = new String [1000];
- int h, k, i=0,count=0, temporary;
- String tmp, inputCDtitle, inputcategory, inputcontainer, inputlocation;
- CsvTest test = new CsvTest();
- test.readFile(CDtitle,category,container,location);
- inputCDtitle = JOptionPane.showInputDialog("Enter item");
- inputcategory = JOptionPane.showInputDialog("Enter Category");
- inputcontainer = JOptionPane.showInputDialog("Enter container");
- inputlocation = JOptionPane.showInputDialog("Enter location");
- for(i=0;i<CDtitle.length;i++){
- if (CDtitle[i]!=null){
- System.out.println(CDtitle[i] + " = " + category[i]+ " = " + container[i]+ " = " + location[i]);
- count++;
- }
- }
- System.out.println(count);
- CDtitle[count+1] = inputCDtitle;
- category[count+1] = inputcategory;
- container[count+1] = inputcontainer;
- location[count+1] = inputlocation;
- try {
- out = new FileOutputStream("fileInput.txt");
- p = new PrintStream(out);
- for(h=0; h<CDtitle.length;h++){
- if (CDtitle[h]!=null){
- p.println(CDtitle[h]+ "," + category[h] + "," + container[h]+ "," + location[h]);
- }
- }
- p.close();
- } finally {
- try {
- if (s != null)
- s.close();
- }
- catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- test.readFile(CDtitle,category,container,location);
- for(i=0;i<CDtitle.length;i++){
- if (CDtitle[i]!=null){
- System.out.println(CDtitle[i] + " = " + category[i]+ " = " + container[i]+ " = " + location[i]);
- }
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.*;
- public class CsvTest {
- public void readFile(String CDtitle[],String category[], String container[], String location[]) {
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader("fileInput.txt"));
- String line = null;
- int i=0;
- while ((line = br.readLine()) != null) {
- StringTokenizer st = new StringTokenizer(line, ",");
- CDtitle[i] = st.nextToken();
- category[i] = st.nextToken();
- container[i] = st.nextToken();
- location[i] = st.nextToken();
- i++;
- }
- }
- catch (FileNotFoundException ex) {
- ex.printStackTrace();
- }
- catch (IOException ex) {
- ex.printStackTrace();
- }
- finally {
- try {
- if (br != null)
- br.close();
- }
- catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }