我的应用程序有时会因此错误而崩溃:这是一个基本的异步 http 请求,用于在 url 上收集图片。
04-18 14:47:51.336: ERROR/AndroidRuntime(10112): FATAL EXCEPTION: AsyncTask #4
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4865)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:979)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4306)
at android.view.View.invalidate(View.java:10519)
at android.view.View.setFlags(View.java:8635)
at android.view.View.setVisibility(View.java:5647)
at com.advertising.AdActivity.onPause(AdActivity.java:122)
at com.advertising.AdActivity.close(AdActivity.java:355)
at com.advertising.AdActivity.onImageFailure(AdActivity.java:470)
at com.advertising.http.tasks.ImageHttpTask.raiseOnFailure(ImageHttpTask.java:74)
at com.advertising.http.tasks.ImageHttpTask.doInBackground(ImageHttpTask.java:52)
at com.advertising.http.tasks.ImageHttpTask.doInBackground(ImageHttpTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
还有我的 DoInbackground :
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
HttpResponse response;
try {
HttpGet request = new HttpGet(urldisplay);
response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
mIcon11 = BitmapFactory.decodeStream(inputStream);
inputStream.close();
} catch (Exception e) {
raiseOnFailure(e, ErrorType.AD_ERROR);}
return mIcon11;}
编辑:这是我的 inPostExecute/raiseOnSuccess/raiseOnFailure :
@Override
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
raiseOnSuccess(bmImage);
}
private void raiseOnSuccess(ImageView imageView) {
if (this.imageHttpDelegate != null) {
this.imageHttpDelegate.onImageSuccess(imageView);
} else {
Logger.d("Successfull image received.");
}
}
private void raiseOnFailure(Throwable throwable, ErrorType errorType) {
if (this.imageHttpDelegate != null) {
this.imageHttpDelegate.onImageFailure(throwable, errorType);
} else {
if (throwable.getMessage() != null) {
Logger.d(throwable.getMessage());
}
}
}
你能帮我吗?我不说她为什么会崩溃。