Results 1 to 3 of 3
- 01-20-2011, 01:26 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 10
- Rep Power
- 0
Newbie JCreator NoSuchElementException Help!
I'm trying to run a project that involves using no global variables other than the import ones seen below. It's supposed to read a text file with three lines of words. (I've attached it) and then scan them and add a certain suffix or turn the words plural depending on their endings. I have the project running but it seems that it won't read the next line in the input file, and gives me this error.
--------------------------------------------------------------------------
XQAC ZVM
Original String: XQAC ZVM
Plural: XQACCH
Suffix: XQCZVM
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenize r.java:332)
at VowelsRUsNoGlobals2.main(VowelsRUsNoGlobals2.java: 47)
Process completed.
--------------------------------------------------------------------------
The output should look like that first bit of the out put but with three different lines. I tried following the NoSuchElementException, but I am new and still having trouble. Here is the code, any and all help is greatly appreciated!
--------------------------------------------------------------------------
import java.io.*;
import java.util.StringTokenizer;
import java.util.HashSet;
public class VowelsRUsNoGlobals2
{
public static void main (String args[]) throws IOException
{
String suffix = new String();
String suffixR = new String();
String word = new String();
String wordR = new String();
String wordPlural = new String();
String wordSuffix = new String();
String firstLetter = new String();
String lastLetter = new String();
String testLetter = new String();
String vowelSeries = new String();
String consonantSeries = new String();
String line = new String();
FileInputStream inFile;
InputStreamReader inReader;
BufferedReader reader;
StringTokenizer strTkn;
HashSet vowels = null;
int leftmostIndex = 0;
inFile = new FileInputStream ("C://!!VHSAPCSData/Vowels.txt");
inReader = new InputStreamReader (inFile);
reader = new BufferedReader (inReader);
line = null;
line = reader.readLine();
strTkn = new StringTokenizer(line);
while (line != null) {
if (line == null) {
break;
}
word = strTkn.nextToken();
suffix = strTkn.nextToken();
System.out.println (line);
vowels = new HashSet();
vowels.add("A");
vowels.add("C");
vowels.add("S");
vowels.add("L");
wordPlural = word;
wordSuffix = word;
for (int i = 0; i < word.length(); i++) {
wordR = word.substring(i, i+1) + wordR;
}
for (int i = 0; i < suffix.length(); i++) {
suffixR = suffix.substring(i, i+1) + suffixR;
}
if (vowels.contains(wordR.substring(0,1)) == false) {
if (vowels.contains(wordR.substring(1,2)) == false) {
lastLetter = wordR.substring(0,1);
wordPlural = wordR.concat(lastLetter);
wordPlural = wordR.concat("H");
System.out.print("plural: " + wordR);
if (vowels.contains(suffixR.substring(1,2)) == false) {
vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
vowelSeries = vowelSeries.substring(1, vowelSeries.length());
wordSuffix = wordSuffix.substring(0, leftmostIndex);
wordSuffix = wordSuffix.concat(vowelSeries);
wordSuffix = wordSuffix.concat(suffix);
System.out.println("Suffix: " + wordSuffix);
}else{
firstLetter = suffix.substring(0,1);
wordSuffix = suffix.concat(firstLetter).concat(word);
System.out.println("Suffix: " + wordSuffix);
}
}else{
System.out.println("Original String: " + line);
wordPlural = word.concat("GH");
System.out.println("Plural: " + wordPlural);
wordSuffix = word.concat(suffix);
System.out.println("Suffix: " + wordSuffix);
}
}else{
if (vowels.contains(wordR.substring(1,2)) == true) {
for (int i = 0; i < wordR.length(); i++) {
if (vowels.contains(wordR.substring(i, i+1))) {
leftmostIndex++;
}else{
break;
}
}
System.out.println("Original String: " + line);
lastLetter = wordR.substring(0,1);
wordPlural = word;
wordPlural = wordPlural.concat(lastLetter);
wordPlural = wordPlural.concat("H");
System.out.println("Plural: " + wordPlural);
if (vowels.contains(suffixR.substring(1,2)) == false) {
vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
vowelSeries = vowelSeries.substring(1, vowelSeries.length());
wordSuffix = wordSuffix.substring(0, leftmostIndex);
wordSuffix = wordSuffix.concat(vowelSeries);
wordSuffix = wordSuffix.concat(suffix);
System.out.println("Suffix: " + wordSuffix);
}else{
firstLetter = suffix.substring(0,1);
wordSuffix = suffix.concat(firstLetter).concat(word);
System.out.println("Suffix: " + wordSuffix);
}
}else{
System.out.println("Original String: " + line);
wordPlural = word.substring(0, word.length()-1);
wordPlural = wordPlural.concat("G");
System.out.println("Plural: " + wordPlural);
if (vowels.contains(suffixR.substring(1,2)) == false) {
firstLetter = suffix.substring(0,1);
wordSuffix = wordSuffix.concat(firstLetter);
wordSuffix = wordSuffix.concat(suffix);
System.out.println("Suffix: " + wordSuffix);
}else{
suffix = suffix.substring(1, suffix.length());
wordSuffix = word;
wordSuffix = word.concat(suffix);
System.out.println("Suffix: " + wordSuffix);
}
}
}
}
}
}
- 12-18-2012, 03:05 PM #2
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
Re: Newbie JCreator NoSuchElementException Help!
I believe I have a solution to your problem. Instead of using the import statement you did for the infile, try doing this:
Add these three import statements:
import java.util.*;
import java.io.*;
import java.lang.*;
Use this for importing your file
Scanner infile = new Scanner(new File ("Vowels.txt"));
from there use statements such as
int x = infile.nextInt();
String s = infile.nextLine();
and others to call your text file. It leaves much less room for error.
- 12-18-2012, 05:44 PM #3
Re: Newbie JCreator NoSuchElementException Help!
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Java Error: NoSuchElementException
By xpngamer in forum New To JavaReplies: 6Last Post: 03-19-2009, 07:37 PM -
[SOLVED] why am i getting this exception" java.util.NoSuchElementException
By ariz in forum New To JavaReplies: 5Last Post: 02-27-2009, 05:19 AM -
Exception in thread "main" java.util.NoSuchElementException
By vileoxidation in forum New To JavaReplies: 5Last Post: 09-17-2008, 07:29 AM -
Exception in thread "main" java.util.NoSuchElementException
By ragav in forum New To JavaReplies: 4Last Post: 06-08-2008, 02:19 PM -
[SOLVED] Exception in thread "main" java.util.NoSuchElementException
By thevoice in forum New To JavaReplies: 5Last Post: 05-14-2008, 01:43 PM


LinkBack URL
About LinkBacks


Bookmarks