一位客户报告了一个奇怪的错误。在 AsyncTask 中执行普通 AndroidHttpClient.execute() 时,应用程序崩溃,他得到以下堆栈跟踪
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at android.net.http.AndroidHttpClient.isMmsRequest(AndroidHttpClient.java:257)
at android.net.http.AndroidHttpClient.checkMmsSendPermission(AndroidHttpClient.java:290)
at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:296)
at com.xxx.xxx.MyClass$MyHandler.doWork(MyClass.java:325)
at com.xxx.xxx.NetworkRequestHandler$AsyncTaskForRequestHandler.doInBackground(NetworkRequestHandler.java:532)
at com.xxx.xxx.utils.network.NetworkRequestHandler$AsyncTaskForRequestHandler.doInBackground(NetworkRequestHandler.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
... 3 more
为什么调用 checkMMSSendPermission 和 isSmsRequest?我们根本没有使用彩信和短信,应用程序没有这些权限,我猜这就是它崩溃的原因。这适用于我们所有其他 99.9% 的用户。
代码看起来像这样
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
InputStream inputStream = null;
try
{
HttpPost request = new HttpPost(urlString);
prepareURLRequest(request);
HttpResponse response = client.execute(request);
mResultStatus = response.getStatusLine().getStatusCode();
inputStream = response.getEntity().getContent();
...
欢迎任何帮助
更新
这似乎只影响索尼 Xperia Z、Z1 和 ZR 手机。显然,在收到 Android 4.3 的更新后问题开始出现。拥有这些手机的人都无法使用我们的应用程序,但除此之外,它可以正常工作。