Weird problem with J2ME app

Hi all,

I have this really weird problem with the following application.

In my application, i do the following:

ReadGPSModel readGpsModel =new ReadGPSModel();

FCTextBox textBox =new FCTextBox("GPS data",512,0);

programView.getDisplay().setCurrent(textBox);

the ReadGPSModel looks like this:

import java.util.Vector;

import FCTextBox;

import EmptyBufferException;

publicclass ReadGPSModel{

private Vector records =new Vector();

private Vector storedRecords =new Vector();

privatefinallong STOREINTERVAL = 60;// store data every 60 seconds

private FCTextBox textBox;

public ReadGPSModel(){

}

publicvoid setOutputBox(FCTextBox textBox){

this.textBox = textBox;

}

public Vector getRecords(){

return storedRecords;

}

publicvoid addRecord(RecordBuffer buffer){

try{

boolean store =true;

if(records.size() > 0){

String lastDateTime = ((Record)records.elementAt(records.size()-1)).dateTimeOfFix;

if(lastDateTime.equals(((Record)buffer.getRecord()).dateTimeOfFix)){

store =false;

// only store once every second at max, if it's in the same second, skip it

}

}

if(store){

records.addElement(buffer.getRecord());

System.out.println(records.size());

}

}catch (EmptyBufferException e1){

// TODO Auto-generated catch block

e1.printStackTrace();

}

if(records.size() > 1){

Record startRec = (Record)records.elementAt(0);

Record endRec = (Record)records.elementAt(records.size() - 1);

if(startRec.dateTimeOfFix.length() > 8 && endRec.dateTimeOfFix.length() > 8){

int startMin = Integer.parseInt(startRec.dateTimeOfFix.substring(3,5));

int startSec = Integer.parseInt(startRec.dateTimeOfFix.substring(6,8));

int endMin = Integer.parseInt(endRec.dateTimeOfFix.substring(3,5));

int endSec = Integer.parseInt(endRec.dateTimeOfFix.substring(6,8));

if((endMin * 60 + endSec) > (startMin * 60 + startSec + STOREINTERVAL)){

System.out.println("aggregating data");

// aggregate the data

double totalSpeed = 0;

int c = 0;

double totalLat = 0;

double totalLong = 0;

// somewhere down here, the application crashes

for(int i=0;i<records.size();i++){

try{

Record thisRec = (Record)records.elementAt(0);

totalSpeed += Double.parseDouble(thisRec.groundSpeed);

totalLat += Double.parseDouble(thisRec.lattitude);

totalLong += Double.parseDouble(thisRec.longitude);

c++;

}catch(Exception e){e.printStackTrace();}

}

StoredRecord sr =new StoredRecord();

try{

sr.nrOfMeasurements = c;

sr.lattitude = totalLat / c;

sr.longitude = totalLong / c;

sr.speed = totalSpeed / c;

}catch(Exception e){

}

sr.startDateTime = ((Record)records.elementAt(0)).dateTimeOfFix;

sr.endDateTime = ((Record)records.elementAt(records.size()-1)).dateTimeOfFix;

System.out.println(sr.startDateTime +"," + sr.endDateTime +"," + sr.nrOfMeasurements +"," + sr.lattitude +"," + sr.longitude +"," +sr.speed);

storedRecords.addElement(sr);

textBox.setString("nr of records: "+storedRecords.size());

records =new Vector();

}

}

}

}

}

Now, if I run this application I donot see a text box appear. However, when I comment the part from the addRecord method, below the comment// somewhere down here, the application crashes

, Ido see the text box appear. Can anybody explain why this happens?

I tried to run this app in an emulator (mpowerplayer with avetanaBluetooth), and the app works like a charm there...>

[6791 byte] By [chris_van_hinsbergena] at [2007-11-27 3:16:05]
# 1
Well, another day of trying to fix this, but still no luck. I thought of the ideas that dividing by c causes the problem if c = 0, but this would not explain the problem as the program fails, even if addRecord is not called.Anybody?
chris_van_hinsbergena at 2007-7-12 8:18:38 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Have you tried to follow the code advancement with debugger?By using breakpoint you can see where the code crash and why.Also you must print stacktrace of all exception in order to see if an exception occurs.
PeppeMEa at 2007-7-12 8:18:38 > top of Java-index,Java Mobility Forums,Java ME Technologies...