6 Replies Latest reply: Dec 23, 2006 8:47 AM by 807607 RSS

    Array Expander Issues.

    807607
      Hi there ...

      this is how I am adding stuff.
      class CallRecordInfo {
        String from;
        String to;
        double duration;
      
        CallRecordInfo(String f, String t, double d) {
          from = f;
          to = t;
          duration = d;
        }
      }
      
      public class testReader{
           
           int CRdbSize = 2;//CRdbSize = Call Records Database Size ...
             int numRecords = 0; // number of entries in CDdb array
             CallRecordInfo CRdb[] = new CallRecordInfo[CRdbSize];
        
             void addCallRecord(String from, String to, double dur) {
             
             boolean LimitReached = (numRecords == CRdbSize);
             if (LimitReached)
                               {
                                         int tsize = CRdb.length+1;
                                      CallRecordInfo tempCRdb[] = new CallRecordInfo[tsize];
                                      System.arraycopy(CRdb, 0, tempCRdb, 0, CRdb.length);
                                      CRdb = tempCRdb;
                                        CRdb[numRecords] = new CallRecordInfo(from, to, dur);
                                          numRecords++;
                                          numRecords = numRecords-1;     
                            }
           else {
                         CRdb[numRecords] = new CallRecordInfo(from, to, dur);
                           numRecords++;          
           }
          }
      okay .. basically I don't know how long the array will be hence, I did the array expanding code as you can see. I have another method (called find) to search for records by "From". Initially I have 11 sets of record. So if I set the int CRdbSize above 11. The find method works properly. However if its below 11 which is when the boolean kicks in to expand the array, I think the array gets jumbled up or something, as then on calling find method, it doesn't return the right values.
      I understand the error is when I'm copying the array, but I'm not sure what it is.

      Secondly, I tried to achieve similar result using vector. However like the Class CallRecordInfo has been cast to the array, I don't know how to do it for the vector hence be able to search for the values.

      Any suggestions? thank you :)