If anyone is familar with programming in java..
- Akaran_D
- Way too much time!
- Posts: 4151
- Joined: July 3, 2002, 2:38 pm
- Location: Somewhere in my head...
- Contact:
If anyone is familar with programming in java..
Could you drop me a PM?
Have a bug that's been ticking me off for days that I can't seem to work around.
edit: Specifically, while/for loop & a file reading issue with a null pointer exception error.
Have a bug that's been ticking me off for days that I can't seem to work around.
edit: Specifically, while/for loop & a file reading issue with a null pointer exception error.
Akaran of Mistmoore, formerly Akaran of Veeshan
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
- Akaran_D
- Way too much time!
- Posts: 4151
- Joined: July 3, 2002, 2:38 pm
- Location: Somewhere in my head...
- Contact:
Code: Select all
public static void LoadFile()
{
String Filename;
TextInputFile LoadedFile;
Stdout.println("Enter file to load...");
Filename = Stdin.readLine();
LoadedFile = new TextInputFile(Filename);
Index = new String[100];
VIDA = new int[100];
VPA = new int[100];
VAA = new int[100];
VGA = new int[100];
while (!LoadedFile.eof())
{
for (int i = 0; i <= 100; i++)
{
VIDA[i] = LoadedFile.readInt();
VPA[i] = LoadedFile.readInt();
VAA[i] = LoadedFile.readInt();
VGA[i] = LoadedFile.readInt();
Stdout.println(VIDA[i]);
Stdout.println(VPA[i]);
Stdout.println(VAA[i]);
Stdout.println(VGA[i]);
}
Stdout.println("End of file");
LoadedFile.close();
}
}
I'm only a first semester programmer and my teacher is a brilliant man but can't explain his way out of a plastic bag sometimes. He hates to give us actual code, wants us to 'figure it out' on our own using what we've found that works.
edit: If I remove the For loop, it's fine, and doesn't attempt to read past the file. However, then it doesn't scale the i values for the arrays.
Akaran of Mistmoore, formerly Akaran of Veeshan
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
- Akaran_D
- Way too much time!
- Posts: 4151
- Joined: July 3, 2002, 2:38 pm
- Location: Somewhere in my head...
- Contact:
Answer:
Because that is the length my professor told me to do it. I spent two hours figuring out an algorithm that would calculate the number of lines in the file (each data entry is 4 lines, each line needs to go into an array), showed it to him, and he's like, "Oh, just take that out and set the value to 100 and be done with it".
I'll give that a try right now.
edit: That worked, thanks Ten. Enjoy the VV's.
Because that is the length my professor told me to do it. I spent two hours figuring out an algorithm that would calculate the number of lines in the file (each data entry is 4 lines, each line needs to go into an array), showed it to him, and he's like, "Oh, just take that out and set the value to 100 and be done with it".
I'll give that a try right now.
edit: That worked, thanks Ten. Enjoy the VV's.
Akaran of Mistmoore, formerly Akaran of Veeshan
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
I know I'm good at what I do, but I know I'm not the best.
But I guess that on the other hand, I could be like the rest.
I'm not familiar with java, but if it is similar to C, your "for" should have been :
for (i = 0; i < 100; i++)
vs. i <= 100
You're arrays were defined as 100 (which is numbered 0-99)
So your 0 through 100 inclusive is 101 elements where element "100" isn't defined since max is 99.
Don't know if this was your problem for java or not, but if you want to try to go back to your using "for", try removing the "=".
for (i = 0; i < 100; i++)
vs. i <= 100
You're arrays were defined as 100 (which is numbered 0-99)
So your 0 through 100 inclusive is 101 elements where element "100" isn't defined since max is 99.
Don't know if this was your problem for java or not, but if you want to try to go back to your using "for", try removing the "=".
Agreed, but I'm not going to coach him on style in a language I don't know. =DTenuvil wrote:Why would you need the inner loop anyway? Since processing is stopped by the eof condition, and all you need to do is increment the counter to fill the array nodes, it's inelegant to have a separate for loop inside the while (!eof) loop.
You audit code? In that case you are probably more qualified. =D Oh the horrors I bet you've seen! =DCourse what do I know, I'm not a programmer, I'm an auditor
-=Lohrno
-
- Way too much time!
- Posts: 2774
- Joined: September 30, 2002, 6:58 pm
- XBL Gamertag: launchpad1979
- Location: Sudbury, Ontario
Well I am a programmer. One possibility is that once you enter you eof loop, you begine to enter your second loop for 100 times. If by any chance you have 1 left over, you re-enter that enter for/next loop and read 100 more times, even though you might only of had 1 line to read.
Or, this might happen:
- Enter EOF loop
- Read 100 times
- Closes file.
- EOF checks to see if File is EOF but it cannot (since its closed) and returns an error
You might run into some problems later on so it would be wise to get rid of it.
Or, this might happen:
- Enter EOF loop
- Read 100 times
- Closes file.
- EOF checks to see if File is EOF but it cannot (since its closed) and returns an error
You might run into some problems later on so it would be wise to get rid of it.
Last edited by Lynks on November 23, 2004, 5:43 pm, edited 1 time in total.
heh, I keep the fact that I can audit code a secret from my corporate masters, otherwise I'd be looking at an 80 hour workweek. 
I audit the IT environment, generally limited to information security, program change process, system development methodologies, and operations procedures. If you've heard of Sarbanes-Oxley or 404 reviews, that's what I do.

I audit the IT environment, generally limited to information security, program change process, system development methodologies, and operations procedures. If you've heard of Sarbanes-Oxley or 404 reviews, that's what I do.