android.view.ViewRoot$CalledFromWrongThreadException:

假如想象 提交于 2019-12-01 01:49:41

In

       protected InputStream doInBackground(String... params)

You have

      stream = getQueryResults(Base_URL);

Then In getQueryResults you have

    catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
            tryagain();

        }

The In tryagain you have

    public void tryagain() {
    setContentView(R.layout.tryagain);

You cannot update/access ui from a background thread. That is why you are getting that exception.

Also you should re consider your design. If you have setContentView more than once in the same activity re consider your design.

Also instead of mutiple try blocks have one try block and multiple catch blocks.

Not sure what you want but you are calling publishProgress more than once.

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

Looks like you are trying to update the UI on a background Thread like in doInBackground() of your AsyncTask. You can't do this. You need to update the UI on a UI Thread. Use any of the other AsyncTask methods to do this such as

onPreExecute()

onProgressUpdate()

or

onPostExecute()

AsyncTask Docs

you may also want to see

Processes and Threads

You are trying to update an UI element from a Thread that is not the UI Thread.

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