|
L6
Nov 2, 2001 14:31:39 GMT -5
Post by Sylph on Nov 2, 2001 14:31:39 GMT -5
am i the only one who has problems with this question? i keep getting null pointer exception. what is the end of file called? my prof said it was called null. how do u exit a loop when u reach the end of a file?
|
|
|
L6
Nov 2, 2001 21:25:20 GMT -5
Post by Majin_Blues on Nov 2, 2001 21:25:20 GMT -5
what's your format for reading lines?
it might be your condition's:
(inputData != null) for while loop
(inputData == null;) for a for loop - not inputData.equals(null)
|
|
|
L6
Nov 3, 2001 10:17:29 GMT -5
Post by Sylph on Nov 3, 2001 10:17:29 GMT -5
u got it bang on my problem!!! thanks a lot! ;D ;D i put inputData.equals(null) instead. but r u sure it changes for while vs for loops?? i thought it was the same.
|
|
|
L6
Nov 3, 2001 11:12:48 GMT -5
Post by Majin_Blues on Nov 3, 2001 11:12:48 GMT -5
what a lucky guess! ;D
it'd be different between while and for loops. If the while loop was "while (blah == null)", it would mean that if the input was still null, do the commands... the for loops say when to stop - that is when (blah == null), stop doing commands
|
|
|
L6
Nov 3, 2001 12:12:30 GMT -5
Post by Sylph on Nov 3, 2001 12:12:30 GMT -5
no, i think the condition should be true for both the while and for loops to execute. that's how it worked on my programs (and they work now), and that's how it was on that tutorial week 8 in-class exercise about the roaches everywhere, right?
|
|
|
L6
Nov 3, 2001 14:48:13 GMT -5
Post by Brutal_Chicken on Nov 3, 2001 14:48:13 GMT -5
You know, instead of figuring out how many weeks till the roaches have a small army couldn't they have had us figure out how many bottles of "Raid" it would take to kill them?
Anyways, about the text file for the input. The ever-clear handout says that if the line contains a capital letter then it's printed out. So it could be like;
"yabba dabba Dooo" and it'd still be printed?
So that means the whole thing is taken in as a string? That doesn't make sense. How would you know if the text file moved on to the new line? The FileReader accounts for that?
So, what I'm doing is that I'm assuming that each new line is like pressing "Enter" when you're inputing, meaning each line is just one long string until it ends.
|
|
|
L6
Nov 3, 2001 17:55:34 GMT -5
Post by Majin_Blues on Nov 3, 2001 17:55:34 GMT -5
no, i think the condition should be true for both the while and for loops to execute. you're right... my mistake... ;D got confused when i used "!="...
|
|
|
L6
Nov 3, 2001 18:06:54 GMT -5
Post by Majin_Blues on Nov 3, 2001 18:06:54 GMT -5
"yabba dabba Dooo" and it'd still be printed? So that means the whole thing is taken in as a string? That doesn't make sense. How would you know if the text file moved on to the new line? The FileReader accounts for that? yes yes - it asks if the line contains a capital letter. besides, file reader reads it line by line, ending with the character for a new line. if you're thinking it might go to a new line prematurely in a text file, that's the word wrap. that doesn't affect the actual file, just the way it shows up on your screen.
|
|
|
L6
Nov 3, 2001 19:15:20 GMT -5
Post by Brutal_Chicken on Nov 3, 2001 19:15:20 GMT -5
EDIT: You know what? I'm forgetting things I already know.
|
|
|
L6
Nov 3, 2001 20:03:55 GMT -5
Post by Majin_Blues on Nov 3, 2001 20:03:55 GMT -5
no problemo... happens to me more often than anyone would think...
i have a shorter memory span than a computer with 1 kb of ram
|
|
|
L6
Nov 4, 2001 17:18:47 GMT -5
Post by Brutal_Chicken on Nov 4, 2001 17:18:47 GMT -5
Well, looks like I should've written down what I was thinking when I wrote that up there.
This is what I have:
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
FileReader textFile = new BufferedReader (new FileReader(in.readLine());
private String line = textFile.readLine();
In my twisted brain this makes sense... sorta. But I do get a whole bunch of errors. I know you need the first line for input so then the next line creates a filereader where you can input the name (and path?) of the text file.
EDIT: Hmm, I've seem to have forgotten the second BufferedReader for the file. Ok, assume it's there.
|
|
|
L6
Nov 4, 2001 19:12:57 GMT -5
Post by Majin_Blues on Nov 4, 2001 19:12:57 GMT -5
BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); FileReader textFile = new BufferedReader (new FileReader(in.readLine()); private String line = textFile.readLine(); what's the error message exactly? you have to create a BufferedReader object, not a FileReader object: BufferedReader textFile = new BufferedReader(new FileReader(in.readLine()); (you had FileReader textFile instead)
|
|
|
L6
Nov 4, 2001 21:24:53 GMT -5
Post by Brutal_Chicken on Nov 4, 2001 21:24:53 GMT -5
Hmm, that was one of the first "versions" of this frustrating assignment. Frustrating not because of what you have to do but with what I have to do it with. Would you happen to know of any better IDE's out there? Preferrably somewhere in the price range of free?
|
|
|
L6
Nov 4, 2001 21:37:38 GMT -5
Post by Majin_Blues on Nov 4, 2001 21:37:38 GMT -5
i'm using realJ and i seem to coping just nicely... but i have to do some last minute testing at the CDF lab before handing it in
or you can just burn codewarrior from someone...
|
|
|
L6
Nov 4, 2001 21:44:30 GMT -5
Post by Brutal_Chicken on Nov 4, 2001 21:44:30 GMT -5
Heh, all my burning sources focus primarily on games then only major apps. CW doesn't seem to be too high on their list. Ha well. CDF it is for me.
|
|