下面顯示的函數有什麼問題嗎?在調試器中運行此代碼時發現的唯一錯誤是「java.lang.NullPointerException:0」。我最後花了好幾個小時弄清楚「是什麼原因導致了這個錯誤」,有人請求幫助。J2me RecordStore錯誤:java.lang.NullPointerException:0 - 下面的代碼有什麼問題
public String[] addRECORD(String mydata){
String[] output = null;
try {
RecordStore rs = null;
String sb = null;
RecordStore.openRecordStore(REC_STORE, true);
if (mydata.equals("Logged")) {
byte[] recData = new byte[5];
int len;
for(int i = 1; i <= rs.getNumRecords(); i++){
if(rs.getRecordSize(i) > recData.length){
recData = new byte[rs.getRecordSize(i)];
}
len = rs.getRecord(i, recData, 0);
sb += new String(recData, 0, len);
}
if (sb != null) {
output[0] = "rexists";
output[1] = sb.trim();
} else {
output[0] = "notlogged";
output[1] = sb.trim();
}
}else{
byte[] rec = mydata.getBytes();
try{
rs.addRecord(rec, 0, rec.length);
}catch (Exception e){}
output[0] = "radded";
output[1] = mydata;
}
rs.closeRecordStore();
} catch (RecordStoreException ex) {
responder(ex.getMessage());
}
return output;
}
錯誤發生在哪條線上? – millimoose