android.view.ViewRoot$CalledFromWrongThreadException:

后端 未结 3 1886
灰色年华
灰色年华 2021-01-07 12:48

I\'m getting an error in my logcat stating:

java.net.UnknownHostException: apps.example.com
09-13 14:57:28.970: W/System.err(3823): android.view.ViewRoot$Cal         


        
3条回答
  •  甜味超标
    2021-01-07 13:40

    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.

提交回复
热议问题