runtime exception can't create handler inside thread that has not called looper.prepare error

后端 未结 1 781
小蘑菇
小蘑菇 2021-01-29 06:07

I am trying to upload a photo with a few other EditText. I got the sample code from an online example and edited it alittle but I\'m receiving this error:

08-29         


        
相关标签:
1条回答
  • 2021-01-29 06:23

    Probably the error arise because of this line

     Toast.makeText(getApplicationContext(),
                        e.getMessage(),
                        Toast.LENGTH_LONG).show();
    

    inside doInBackground.Toast has to been shown on the UIThread. Instead you are using the doInBackground thread to show it. In general, all the operations regarding the UI have to be executed on the UI Thread. If you want to fix, you could use an handler to post a runnable on the UI Thread queue that shows a Toast

    0 讨论(0)
提交回复
热议问题