• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with an exception

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone. i am working on an extra-credit lab for my java course and i am in need of assistance.
i am just not getting this part right here.

what i want that part of the code to do is read in a whole line from a comma separated value text file(format -- username,password) and store it to the string userOrPass and then break it up and call an instance of another class (instance is the log. ) and pass a string to it to store it in an array of strings and then do the same with passwords.
i keep getting NoSuchElementExceptions
is there something in the code that some of you notice or should i post both classes?
thanks in advance for any help
adam
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

readValue is a StringTokenizer that will operate on the string in userOrPass, which is the empty string, so calling nextToken() on it even once will give the exception you see.
I think what you intended is to have a StringTokenizer for each individual line, in which case what you need to do is to move that entire line of code inside the while loop, at the top.
 
Adam Jones
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i am having a terrible time with this
i am not sure if the following is what anyone else would do, but it is what i did. if you could, would you take a quick look at it and see if there is anything obvious that i am really messing up
it compiles and when i try to run it i get a NoSuchElementException. in the while loop when i try to fill my String arrays with usernames and passwords. i thought it looked fine but it is not
anyways, any help offered would be greatly appreciated

thank you
adam
[ October 14, 2003: Message edited by: Adam Jones ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just looking at the while loop, it looks OK -- if every single line in the file looks like "foo,bar". If there's a single blank line at the end, you'll see that error. For debugging purposed, you could print out something like "*" + userOrPass + "*" on each iteration, just to see if every line is actually valid. To fix this in the code, you'd want to check if readValue().getNumberOfTokens() returns 2; if not, skip that line (or report an error.)
 
Adam Jones
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, one more question and then i should have this....i think
i have changed this part and now it works....well, kind of

after that it will read the file in correctly and store the strings where they need to go, but then when i try to compare them i am getting a NullPointerException....i believe this means a programmer error in any case, so if you could take a quick look back through it i would be thankful
thank you for all of your help
adam
[ October 14, 2003: Message edited by: Adam Jones ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic