android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

给你一囗甜甜゛ 提交于 2019-12-01 10:33:32

This is your problem:

for(int l=0;l<4;l++){
    if(listObject.get(l).getImage()!="")
        image.setImageBitmap(bitmap);
}

Short answer: just like the exception says, you're trying to manipulate a view in the wrong thread. Do it in the right thread (UI thread).

Long answer: In an AsyncTask the right places to do view manipulation are generally onPreExecute, onProgressUpdate and onPostExecute. doInBackground is not usually a good place to modify views. You could call back to the UI thread in one of many ways (for example you could use post). However, that block of code that you posted doesn't make a whole lot of sense to me in general, and you haven't shown enough context to explain what it is, what listObject is, etc.

You have some other problems too. You seem to be trying to read the data in twice in a row in two different ways... Also, I imagine your while condition is going to give you problems as you're recreating the URL object and as long as you get content back you're going to keep doing it. Assuming that URL doesn't have dynamic content, you'll have an infinite loop.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!