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...>

