我正在做一个AsyncTask,它在尝试执行doInBackground()时抛出一个NPE异常。我已经在Google和Google上寻找答案,只要将null传递给Logcat并感觉我已经处理了错误。我做错了什么
private static class UpdateSequenceNumbers extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
int RecID = 0;
String values = "";
//select rd.RecID from T_ResultsSummary rs
//inner join T_ResultsSummaryHistory rsh on rsh.LocalSumID = rs._id
//inner join T_ResultsDetail rd on rd.LocalHisID = rsh._id
//where Value = '-1' and rd.Comments = 'AutoNum' and rd.Active = 1 and SurveyID in (1,2,3,4) and
//rd.RecID <> -1
Cursor c = DataBaseConnector.query(params[0]);
if (c != null) {
if (c.moveToFirst()) {
do {
logMessage("Begin Sequence Numbers Update");
RecID = c.getInt(c.getColumnIndex("RecID"));
values = String.valueOf(RecID);
try {
logMessage("Stored Proc: " + params[1] + "; Values: " + values);
SoapPrimitive response = callProcServiceForScalar(params[1], values);
String sResponse = decryptIfNeeded(response.toString());
logMessage("Stored Proc Response: " + sResponse);
if (sResponse != null) {
if (!sResponse.equals("")) {
if (sResponse.contains("Error=")) {
insertSyncError(sResponse.toString(), params[1], values);
return false;
}
//this is the happy path where all the action happens
else {
String sql = "Update "+ params[2] + " Set Value = " + sResponse + " "//
+ "Where RecID = " + String.valueOf(RecID);
DataBaseConnector.execSQL(sql);
}
} else {
insertSyncError("Blank Response", params[1], values);
return false;
}
} else {
insertSyncError("Null Response", params[1], values);
return false;
}
} catch (Exception e) {
//e.printStackTrace();
String err = (e.getMessage()==null)?"Stored Proc Failed":e.getMessage();
// TODO Auto-generated catch block
insertSyncError(err, "");
return false;
}
} while (c.moveToNext());
logMessage("End Sequence Numbers Update");
}
c.close();
c = null;
}
return true;
}
}
private static void insertSyncError(String errorText, String sqlStatement) {
syncSuccessful = false;
GlobalVars.syncError = errorText != null ? errorText : "Error Occured";
logMessage("Error Text: " + errorText);
logMessage("Error SQL Statement: " + sqlStatement);
if (errorText == null) {
errorText = "";
}
}
这是LogCat:
05-28 16:34:45.010: E/AndroidRuntime(4611): java.lang.RuntimeException: An error occured while executing doInBackground()
05-28 16:34:45.010: E/AndroidRuntime(4611): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.lang.Thread.run(Thread.java:856)
05-28 16:34:45.010: E/AndroidRuntime(4611): Caused by: java.lang.NullPointerException: println needs a message
05-28 16:34:45.010: E/AndroidRuntime(4611): at android.util.Log.println_native(Native Method)
05-28 16:34:45.010: E/AndroidRuntime(4611): at android.util.Log.d(Log.java:138)
05-28 16:34:45.010: E/AndroidRuntime(4611): at com.assistek.ediary.EDiaryDataSync$AllSync.doInBackground(EDiaryDataSync.java:183)
05-28 16:34:45.010: E/AndroidRuntime(4611): at com.assistek.ediary.EDiaryDataSync$AllSync.doInBackground(EDiaryDataSync.java:1)
05-28 16:34:45.010: E/AndroidRuntime(4611): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-28 16:34:45.010: E/AndroidRuntime(4611): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-28 16:34:45.010: E/AndroidRuntime(4611): ... 3 more