|
Re: Copying Strings into an array
|
Posted: Mar 23, 2002 11:05 AM
|
|
It is hard to tell exact error just reading the fragment of your code. However, I can tell you two things: //System.out.println("Tutor code = " + tutorCode); tutors[startInt] = tutorCode; startInt++; //System.out.println("StartInt #" + startInt + " tutor = " + tutors[startInt]);
1. When you are printing first time then you print the value of tutorCode. And, since you have read the value of tutorCode before while loop it is printing correctly. 2. In this line tutors[startInt] = tutorCode; You are storing the tutorCode at startInt position and then in next line you are incrementing startInt by one. However, in second print you are trying to print the tutorCode at the position defined by new ( I mean incremented) startInt. That is, if you stored tutorCode at 1 then you are trying to print it from 2. Of course, you haven't stored tutor code at 2 yet, it will display null value or throw ArrayIndexOutOfBound if your code moves past the array length. So, just place startInt++; code after your second print and it will display the right value. For more help, please post all your code.
Thanks Kishori
|
|