我有这行代码
protected String doInBackground(String... args) {
//unnecessary geocoder calculations
strReturnedAddress = (returnedAddress.getLocality().toString());
}
}
}
return null;
}
它过去 2 天可以正常工作,但今天,由于某种原因,我的应用程序不断崩溃,并且 logcat 将此行显示为错误的来源。当我删除此行时,应用程序不会崩溃。
我应该创建一个新字符串并从 doInBackground 方法返回它并在 onPostExecute 中设置 strReturnedAddress 吗?我真的一无所知,因为这在昨天晚上才有效。
编辑:这是logcat
07-13 16:43:57.480: E/AndroidRuntime(28027): FATAL EXCEPTION: AsyncTask #5
07-13 16:43:57.480: E/AndroidRuntime(28027): java.lang.RuntimeException: An error occured while executing doInBackground()
07-13 16:43:57.480: E/AndroidRuntime(28027): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
07-13 16:43:57.480: E/AndroidRuntime(28027): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.lang.Thread.run(Thread.java:856)
07-13 16:43:57.480: E/AndroidRuntime(28027): Caused by: java.lang.NullPointerException
07-13 16:43:57.480: E/AndroidRuntime(28027): at com.example.realapptest1.MainActivity$GetCurrentCity.doInBackground(MainActivity.java:407)
07-13 16:43:57.480: E/AndroidRuntime(28027): at com.example.realapptest1.MainActivity$GetCurrentCity.doInBackground(MainActivity.java:1)
07-13 16:43:57.480: E/AndroidRuntime(28027): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-13 16:43:57.480: E/AndroidRuntime(28027): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-13 16:43:57.480: E/AndroidRuntime(28027): ... 4 more