S
S
Sergey2015-10-31 21:07:10
Java
Sergey, 2015-10-31 21:07:10

Why does the application crash after calling AsyncTask?

I'm just confused. I have a main activity and there are asynctasks and they all work great. I created another activity and I’m doing functionality there, and I needed an ajunktask, I wrote a simple one:

private class sendMsg extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            Toast.makeText(getApplicationContext(),"Тест тест",Toast.LENGTH_SHORT).show();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
        }
    }

I call on button OnClick
public void UploadBmp (View view){
        new GetTokenOTOP().execute();
    }

I go into the application, call this activity and press the button and hop
FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime: Process: Sergey.CamEdit, PID: 6989
E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-10-31
@goodwin74

you are accessing the ui thread in doInBackground, replace toast with Log.d

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question