Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No Line Found  RSS feed

 
Christopher Beech
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is the right forum for this or not. I'm trying to type up a program that will help me study japanese. It takes in a text file and does various things with the file. But for some reason, I keep getting a "No Line Found" error. I've been using Java since Spring of 2005 and I believe that this is the first time I've ever encounter this error.

Here's the code I'm using.

Disclaimer: I didn't type up the JapaneseDirTester program. I modified a file I got from the Data Structures And Algorthims class I was in Spring of 2006.









Here's the contents of the file I'm trying to read in:

neko
cat
neko
student
gakusee
um
ano
now
ima
yes
ee
English language
eego
phone
denwa
[ April 15, 2007: Message edited by: Christopher Beech ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you could post the exact text of the error, and maybe indicate in your code which line it is referring to, that may help people figure out what the problem is.
 
Christopher Beech
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake. It's an NoSuchElementException.

And here's the error lines it's giving me:

NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Japanese.<init>(Japanese.java:24)
at JapaneseDirTester.main(JapaneseDirTester.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

Nevermind. I figured out that the error was caused because I had an odd number of words in the file.

Any clue why my remove method is always removing the second line???
And why is it reading in the file last line first???
[ April 15, 2007: Message edited by: Christopher Beech ]

[ April 15, 2007: Message edited by: Christopher Beech ]

[ April 15, 2007: Message edited by: Christopher Beech ]
[ April 15, 2007: Message edited by: Christopher Beech ]
 
Christopher Beech
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bump.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry it has taken such a long time for a reply. I didn't notice your post earlier.

You are quite correct about odd numbers of lines. You are testing for next lines quite correctly with while(inScan.hasNext()), but reading two lines. So if there is an odd number of elements you will have nothing to read and get a NoSuchElementException, as thrown by Scanner. Suggest you alter your input file to have two words on each line.

I think you are getting reverse display because you have set up your JapaneseRecordNode class like a Stack. What you have is. . . and stacks always work in a LIFO fashion (LIFO=last in first out). What you want is a LinkedList, and I think you might get that behaviour with a minor change to the JapaneseRecordNode constructor. What you are looking for is like this:-

baseObject-->node0-->node1-->node2-->etc etc-->nodeN-2-->nodeN-1-->nodeN-->null

Whenever you add a newNode, try this:-
  • if next is null, the new node is put in place of "next."
  • If next is not null, pass "newNode" on to "next" and tell it to add it.
  • This process should recurse until your new node is added as the last node.

  • Adding nodes in the middle of a LinkedList oncce one has a reference to the location is very fast, but finding nodes by a count along the LinkedList, or adding at the end, can be slower because one has to traverse the entire list. You may get better performance if you implement an ArrayedList instead (the java.util.ArrayList class is a good example).

    [edit]Add nodeN-1 and slight formatting corrections[/edit]
    [ April 23, 2007: Message edited by: Campbell Ritchie ]
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!