"Il y a peu de choses qui me soient impossibles..."
Aron Silvester wrote:The output when I run this is:
run:
null null null null BUILD SUCCESSFUL (total time: 0 seconds)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Aron Silvester wrote:The output when I run this is:
run:
null null null null BUILD SUCCESSFUL (total time: 0 seconds)
That's odd, because even if it's wrong (and nothing leaps out at me) I'd expect it to be
null
null
null
null null null null null BUILD SUCCESSFUL...
Are you sure you're running the exact code you showed us?
Winston
Stevens Miller wrote:Runs fine for me, Aron. The code you posted should print five lines, one for each name in your file, and a fifth line with all four names on it. What you describe as your output doesn't show the first four lines, which should appear even if the Strings are all null references. Have you posted exactly what your source code is?
By the way, cross-posting the same question to more than one forum is frowned upon. Some people think it is a pretty big deal, while others don't, but it can lead to people spending time and effort in one forum, trying to help you, after people in the other forum have already solved your problem for you. Best practice is to pick one and stick with it for a given question. I'd recommend coderanch.com, but I'm a bit biased about that.
"Il y a peu de choses qui me soient impossibles..."
Aron Silvester wrote:Okay sorry bout that, I'll keep that in mind next time. My while loop is not executing, I put print statement in the loop and it did not print, so therefore it's not entering the while loop, which I don't know why.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Stevens Miller wrote:Java is pretty good about handling the inconsistent ways that Linux/Unix and Windows handle the "/" and "\" characters, but I wonder if you are having some problem related to that. What operating system are you using? I'm using Windows. Cutting and pasting your posted code, with the only change being from "/Users/regies/NetBeansProjects/Sanchez_Project#2/ListOfNames.txt" to "/Users/smiller/ListOfNames.txt", it runs fine for me.
Use a debugger and step through your code line by line. If the while loop isn't even being entered, it means that the call to inputFile.hasNext() is returning false, which can only mean your Scanner thinks it is looking at an empty File. So, I'm guessing your problem is at Line 22. Use a debugger and let us know what you find there.
Aron Silvester wrote:For my text file I used microsoft word and typed in the strings. I saved it normally. Once saved on my desktop I proceeded to add .txt at the end of the name. Is that how you save the text files for these? Maybe that's causing the problem?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Aron Silvester wrote:For my text file I used microsoft word and typed in the strings. I saved it normally. Once saved on my desktop I proceeded to add .txt at the end of the name. Is that how you save the text files for these? Maybe that's causing the problem?
Possibly. A Word file definitely isn't the same as text. Use Notepad, or alternatively download a text editor - there are gazillions out there, including several that "understand" Java code and display in nice colours for you.
Unfortunately, I'm a Linux user now, so I've forgotten all things Microsoft.
Winston
Aron Silvester wrote:It worked. Thank you guys so much!!!
"Il y a peu de choses qui me soient impossibles..."
Don't get me started about those stupid light bulbs. |