Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Problem With Nextelement (http://www.programmingforums.org/showthread.php?t=1087)

FidI Nov 9th, 2004 10:03 PM

hi!i am trying to make a program that reads a whole file and then it prints the lines one by one.when i am trying to compile the program i am getting an error message that nextElement() symbol cannot be found.any ideas please?thank you!
:)

:

import java.io.*;
import java.util.*;

public class token2
{
        public static void main(String args[]) throws IOException{
 String question;

 StringTokenizer currentString;

        BufferedReader InputData = new BufferedReader(new FileReader("c:/inputData.txt"));


 while ((question = InputData.readLine()) != null){
        currentString = new StringTokenizer(question,"?");

        while (currentString.hasMoreElements())
  System.out.println(question.nextElement());

 }

 }
        }


sykkn Nov 9th, 2004 10:43 PM

it looks like you got two small errors. You forgot to put { after the second while, and you tried to call nextElement() on question, which is a String object, rather than the currentString StringTokenizer object.

:

import java.io.*;
import java.util.*;

public class token2
{
    public static void main(String args[]) throws IOException{
        String question;

        StringTokenizer currentString;

        BufferedReader InputData = new BufferedReader(new FileReader("c:/inputData.txt"));


        while ((question = InputData.readLine()) != null){
            currentString = new StringTokenizer(question,"?");

            while (currentString.hasMoreElements()) {
                System.out.println(currentString.nextElement());
            }
        }
    }
}


FidI Nov 10th, 2004 2:44 AM

worked!!!!thank you very very much!!!!!:) :)


All times are GMT -5. The time now is 12:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC