I have a problem here that's stumping me. OK, more than one. :) But only one for now.

This program reads two input files. The second file is processed first in a loop. Then, I want to use this information to update information in the first file. Here's the section of code in question.....

boolean eof1 = false;
boolean eof2 = false;
int lineCt = 1;
int i2 = 0;
String[] tokens2;

            //  LOOP 1 

while (!eof2) {
    String line2 = buff2.readLine();
    if (line2 == null)
         eof2 = true;
    else {
         String delimiters2 = "\\s\\s+|\\,";
         tokens2 = line2.split(delimiters2);
         for (i2 = 0; i2 < tokens2.length; i2++) {
              switch (i2) {
                 case 0:
                 case 1:
                	System.out.print(tokens2[i2] + "\t");
                		break;
                 }
          }
       System.out.println();
    }
}
System.out.println(" ");
System.out.println(" ");

            // LOOP 2

while (!eof1) {
    String line = buff1.readLine();
    if (line == null)
         eof1 = true;
     else {
         String delimiters = "\\s\\s+|\\,";
         String[] tokens = line.split(delimiters);
         //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//
         //       UPDATE PROCESSING !!!                         //
         //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//
         //==> initial processing loop <==//
         for (int i = 1; i < tokens.length; i++) {
            String answer;
            if (lineCt == 1) {
              	}
            else {
              switch (i) {
                case 13:  // N - move values in 14 to here.
                  tokens[13] = tokens[14];
                  break;
                case 14:  // O - get values from second csv
                   // NOTE: here I try to access info in first loop !!
                  for (i2 = 0; i2 < tokens2.length; i2++) { // <<--  here

                                      }
                case 7:   // H - value in 14 / value in 6
                  answer = doMath1(tokens[14], tokens[6]);
                  tokens[7] = answer;
                  break;
                case 15:  // P - value in 14 / value in 13
                  answer = doMath1(tokens[14], tokens[13]);
                  tokens[15] = answer;
                  break;
                case 16:  // Q - value in 14 / value in 9
                  answer = doMath1(tokens[14], tokens[9]);
                  tokens[16] = answer;
                  break;
                case 17:  // R - value in 14 / value in 12
                  answer = doMath1(tokens[14], tokens[12]);
                  tokens[17] = answer;
                  break;
                }
            }
       }

The first while loop does work. It reads the file and displays the information correctly at the first System.out.println. It does exactly what I want it to do.

It completely reads the file, and at eof, jumps out of the first while loop.

But when I get into the second while loop, and try to access the information read in the first while loop (case 14), it is no longer there. That's when I get the "The local variable tokens2 may not have been initialized." message. Does the array in the first while loop just disappear upon termination of the while loop? Is there a way to keep this array from going away, or do I somehow need to incorporate it's functions into the second while loop?

Thanks in advance...

But when I get into the second while loop, and try to access the information read in the first while loop (case 14), it is no longer there. That's when I get the "The local variable tokens2 may not have been initialized." message.

That is because you only assign the variable a value inside a conditional expression, so the compiler warns that it may not be initialized when you later try to access it. Give it an initial value and the compiler will be happy.

Does the array in the first while loop just disappear upon termination of the while loop?

No, it's still there because you declared it outside of that loop. It would only lose scope if you declared it within that loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.