440,180 Members | 1,016 Online Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

# Java Array Problem

 P: 17 Expand|Select|Wrap|Line Numbers public class Result {     private int countA = 0;     private int countB = 0;     private int statement;     private boolean statusA = false;     private boolean statusB = false;     private int[] arrayA = new int; <= the problem seem like happen at here?     private int[] arrayB = new int; <= the problem seem like happen at here?       public Result()     {       }     public void setA(int valueA)     {         countA = valueA;     }     public void setB(int valueB)     {         countB = valueB;     }     public void setOption(int stm)     {         statement = stm;     }     public void setStatusA(boolean a)     {         statusA = a;     }     public void setStatusB(boolean b)     {         statusB = b;     }     public void resetToFalse()     {         statusA = false;         statusB = false;     }     public void sumTotal()     {         if(statement==1)         {             if(statusA == true)             {                 int temp = arrayA;                 arrayA = temp + 1;                 System.out.println("arrayA is: " + arrayA); <= This line can correctly show increament of the array value everytime i click one time buttonA from another class              }             if(statusB == true)             {                 int temp = arrayA;                 arrayA = temp + 1;                 System.out.println("arrayA is: " + arrayA); <= This line can correctly show increament of the array value everytime i click one time buttonB from another class              }         }         if(statement==2)         {             if(statusA == true)             {                 int temp = arrayB;                 arrayB = temp + 1;                 System.out.println("arrayB is: " + arrayB);             }             if(statusB == true)             {                 int temp = arrayB;                 arrayB = temp + 1;                 System.out.println("arrayB is: " + arrayB);             }         }     }     public  void printReport()     {         System.out.print(arrayA + " " + arrayA + "\n");         System.out.print(arrayB + " " + arrayB);     } } The problem is when i invoke printReport() from another class, the output of the two array become: arrayA: 0 0 arrayB: 0 0 May i know what is the problem cause the output become zero value even though code at line 48 and 54 can print out correct updated output. Apr 6 '08 #1
5 Replies

 Expert 10K+ P: 11,448 [code]The problem is when i invoke printReport() from another class, the output of the two array become: arrayA: 0 0 arrayB: 0 0 May i know what is the problem cause the output become zero value even though code at line 48 and 54 can print out correct updated output. Your class works fine, i.e. it does whatever it has to do; are you sure you are using just one 'Result' object? Possibly you have accidentally created another Result object that does the printing while the first one did the incrementing. kind regards, Jos Apr 6 '08 #2 