473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

NoSuchElementException Error sentinel Loop

Expand|Select|Wrap|Line Numbers
  1.  import java.io.*;
  2. import java.util.*;
  3. public class tryCountLetter {
  4.  
  5.     public static void main(String[]args) throws FileNotFoundException{
  6.  
  7.         Scanner inFile = new Scanner(new FileReader("D:\\My Documents\\Java Saves\\try.txt"));
  8.  
  9.     int counter = 0;
  10.  
  11.     String str=inFile.next();
  12.         while(str!= "-999")
  13.         {
  14.         str = inFile.next();
  15.         System.out.print(str.length());
  16.         }
  17.         inFile.close();
  18.     }
  19.  
  20.     }
this is the error

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1317)
at tryCountLetter.main(tryCountLetter.java:22)

i dont get it?
why does it say NoSuchElementException?

this is what's inside of the try.txt

Im a newbie -999
Sep 18 '08 #1
4 2546
JosAH
11,448 Expert 8TB
You can't compare strings for (in)equality like you did in line twelve. Do this
instead:

Expand|Select|Wrap|Line Numbers
  1. while (!str.equals("-999"))
  2.  
kind regards,

Jos
Sep 18 '08 #2
You can't compare strings for (in)equality like you did in line twelve. Do this
instead:

Expand|Select|Wrap|Line Numbers
  1. while (!str.equals("-999"))
  2.  
kind regards,

Jos
I still received the same error..
I don't get it..
thank you for you immediate response!!
Sep 18 '08 #3
You can't compare strings for (in)equality like you did in line twelve. Do this
instead:

Expand|Select|Wrap|Line Numbers
  1. while (!str.equals("-999"))
  2.  
kind regards,

Jos
by the way i already solved it..thank any way :D
Sep 18 '08 #4
JosAH
11,448 Expert 8TB
by the way i already solved it..thank any way :D
So how did you solve it?

kind regards,

Jos
Sep 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: d.j. | last post by:
This program will not let me use the charater as the sentinel please advise... The error I get is can not convert char to char* # include <iostream.h> int main() { char stname ; //student...
3
by: Mike | last post by:
I am writing this program that first asks the user to type today's exchange rate between U.S. dollars and Japanese yen, then reads U.S. dollar value and converts each. I am attemtping to use 0 or...
13
by: shan | last post by:
Hi to everybody here is my simple doubt What is meant by sentinel control loops ?
7
by: Ben Finney | last post by:
Howdy all, Ned Batchelder blogged about a debate over checking function parameters, and to what extent dynamic typing should be relied upon. I was one of many who commented, but I wrote what...
6
by: Alenik1989 | last post by:
ok i have this code that executes for all # between 0 and 1001 perfectly. it is a cod to find the factors of inputed data and then determine it as a perfect number or not, also it suppose to loop...
4
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at...
6
by: chetah | last post by:
text file Dietel10004 How to Program In Java R IN Dietal & Dietal Prentice Hall 06-09-08 Flanag0204 Java In a Nutshell C OUT David Flanagan O'Reilly 03-06-20 END 99100452 John Smith #5 Hillview...
1
by: Sergiu Ignat | last post by:
Hello, I try to deploy an application through ClickOnce. I use .NET Framework 3.5SP1. In Publish/Prerequisites I require the entire framework (not only the client profile) and checked "Download...
5
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.