0

I am working with ksoap2 webservices,i am getting the exception after some time when i am trying to login my app,this exception raise after some time when i am trying to login my app..

my logcat:

01-20 12:04:40.669: E/AndroidRuntime(5805): FATAL EXCEPTION: AsyncTask #3
01-20 12:04:40.669: E/AndroidRuntime(5805): java.lang.RuntimeException: An  error occured while executing doInBackground()
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at  java.lang.Thread.run(Thread.java:841)
01-20 12:04:40.669: E/AndroidRuntime(5805): Caused by:  java.lang.RuntimeException: Can't create handler inside thread that has not  called Looper.prepare()
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.os.Handler.<init>  (Handler.java:197)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.os.Handler.<init>(Handler.java:111)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.widget.Toast$TN.<init>(Toast.java:324)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.widget.Toast.   <init>(Toast.java:91)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at  android.widget.Toast.makeText(Toast.java:238)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at  com.ufone.ufoneselfcare.MainActivity$AsyncCallWS.doInBackground(MainActivity.java:274)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at c om.ufone.ufoneselfcare.MainActivity$AsyncCallWS.doInBackground(MainActivity.java:1)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-20 12:04:40.669: E/AndroidRuntime(5805):     at  java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-20 12:04:40.669: E/AndroidRuntime(5805):     ... 4 more
01-20 12:04:41.369: E/WindowManager(5805): Activity   com.ufone.ufoneselfcare.MainActivity has leaked window   com.android.internal.policy.impl.PhoneWindow$DecorView{419047a0 V.E.....   R......D 0,0-258,175} that was originally added here
01-20 12:04:41.369: E/WindowManager(5805): android.view.WindowLeaked:  Activity com.ufone.ufoneselfcare.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{419047a0 V.E.....  R......D 0,0-258,175} that was originally added here
01-20 12:04:41.369: E/WindowManager(5805):  at  android.view.ViewRootImpl. <init>(ViewRootImpl.java:345)
01-20 12:04:41.369: E/WindowManager(5805):  at  android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
01-20 12:04:41.369: E/WindowManager(5805):  at  android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
01-20 12:04:41.369: E/WindowManager(5805):  at android.app.Dialog.show(Dialog.java:281)
01-20 12:04:41.369: E/WindowManager(5805):  at  com.ufone.ufoneselfcare.MainActivity$AsyncCallWS.onPreExecute(MainActivity.java:328)
01-20 12:04:41.369: E/WindowManager(5805):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
01-20 12:04:41.369: E/WindowManager(5805):  at android.os.AsyncTask.execute(AsyncTask.java:534)
01-20 12:04:41.369: E/WindowManager(5805):  at  com.ufone.ufoneselfcare.MainActivity.loginAction(MainActivity.java:208)
01-20 12:04:41.369: E/WindowManager(5805):  at com.ufone.ufoneselfcare.MainActivity.access$0(MainActivity.java:167)
01-20 12:04:41.369: E/WindowManager(5805):  at com.ufone.ufoneselfcare.MainActivity$2.onClick(MainActivity.java:134)
01-20 12:04:41.369: E/WindowManager(5805):  at android.view.View.performClick(View.java:4240)
01-20 12:04:41.369: E/WindowManager(5805):  at android.view.View$PerformClick.run(View.java:17739)
01-20 12:04:41.369: E/WindowManager(5805):  at android.os.Handler.handleCallback(Handler.java:730)
01-20 12:04:41.369: E/WindowManager(5805):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-20 12:04:41.369: E/WindowManager(5805):  at android.os.Looper.loop(Looper.java:137)
01-20 12:04:41.369: E/WindowManager(5805):  at  android.app.ActivityThread.main(ActivityThread.java:5140)
01-20 12:04:41.369: E/WindowManager(5805):  at  java.lang.reflect.Method.invokeNative(Native Method)
01-20 12:04:41.369: E/WindowManager(5805):  at  java.lang.reflect.Method.invoke(Method.java:525)
01-20 12:04:41.369: E/WindowManager(5805):  at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-20 12:04:41.369: E/WindowManager(5805):  at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-20 12:04:41.369: E/WindowManager(5805):  at     dalvik.system.NativeStart.main(Native Method)

This is my asynctask class:

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
    @Override
    protected Void doInBackground(String... params) {

        try {

            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet = true;
            Log.d("SelfCare", "request= " + request);
            androidHttpTransport = new HttpTransportSE(URL);
            Log.d("SelfCare", "androidHttpTransport= "
                    + androidHttpTransport);

            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            Log.d("SelfCare", "response= " + response);
            /*
             * Toast.makeText(getApplicationContext(), "Response= " +
             * response, Toast.LENGTH_LONG).show();
             */
            String jsonResponse = "";
            jsonResponse = response.toString();

            // A JSONTokener is needed in order to use JSONObject correctly
            JSONTokener jsonTokener = new JSONTokener(jsonResponse);
            // Pass a JSONTokener to the JSONObject constructor
            JSONObject jsonObj = new JSONObject(jsonTokener);
            JSONArray data = jsonObj.getJSONArray("data");

            if (data != null) {

                // looping through All nodes
                for (int i = 0; i < data.length(); i++) {
                    JSONObject c = data.getJSONObject(i);
                    message = c.getString("message");
                    sessionid = c.getInt("sessionid");
                    saleid = c.getInt("saleid");
                    name = c.getString("name");
                    email = c.getString("email");
                    defaultmsisdn = c.getString("defaultmsisdn");

                    Log.d("SelfCare", "message= " + message);
                    Log.d("SelfCare", "sessionid= " + sessionid);

                }

                /*
                 * Toast.makeText(getBaseContext(), "Success",
                 * Toast.LENGTH_LONG).show();
                 */

            } else {
                Toast.makeText(getBaseContext(), "Error", Toast.LENGTH_LONG)
                        .show();
            }

            /*TextView results = (TextView) findViewById(R.id.login_error);
            results.setText(response.toString());*/

        } catch (Exception e) {
            //alertDialog(e.toString());
            Toast.makeText(getApplicationContext(), e.getMessage(),
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // Log.i(TAG, "onPostExecute");
        // tv.setText(fahren + "° F");

        pDialog.dismiss();
        if (message.equalsIgnoreCase("Login Successful.")) {
            if (defaultmsisdn.equalsIgnoreCase("null") && saleid == 0) {
                et_username.setText("");
                et_password.setText("");
                Intent intent = new Intent(getApplicationContext(),
                        AssociateMsisdn.class);
                intent.putExtra("username", username);
                intent.putExtra("sessionid", sessionid);
                intent.putExtra("name", name);
                intent.putExtra("email", email);
                startActivity(intent);
            //alertDialog("Open the Associate MSISDN Class.");
            } else {
                et_username.setText("");
                et_password.setText("");
                Intent intent = new Intent(getApplicationContext(),
                        MainMenu.class);
                intent.putExtra("name", name);
                intent.putExtra("username", username);
                intent.putExtra("defaultmsisdn", defaultmsisdn);
                intent.putExtra("sessionid", sessionid);
                intent.putExtra("saleid", saleid);
                intent.putExtra("email", email);

                startActivity(intent);
            }
        } else {
            alertDialog(message);
            // Toast.makeText(getApplicationContext(), "" +message ,
            // Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onPreExecute() {
        // Log.i(TAG, "onPreExecute");
        // tv.setText("Calculating...");
        // pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Loading ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        // Log.i(TAG, "onProgressUpdate");
    }

}

and that is the line on which I am getting the exception::

androidHttpTransport.call(SOAP_ACTION, envelope);

Note:- I am getting the exception not regularly, but getting the exception after some time when I am trying to login my app and one more thing when I debug my app then in my catch block this message will be come java.net.sockettimeoutexception

Kaushik
  • 6,150
  • 5
  • 39
  • 54
Farhan Shah
  • 2,344
  • 7
  • 28
  • 54
  • 4
    this is happening as you are trying to display a toast in catch block inside doInBackground method. to display toast you need display from onpostexecute method which runs on UI thread – Rajen Raiyarela Jan 20 '15 at 07:39
  • @RajenRaiyarela dear can i remove the toast in my catch block?but my app is crashed on that line androidHttpTransport.call(SOAP_ACTION, envelope); – Farhan Shah Jan 20 '15 at 07:44
  • @FarhanShah yes ofcourse show toast, change ui and navigate to different activity in onPostexecute – Kaushik Jan 20 '15 at 07:46
  • @Farhan Shah i would suggest comment both the toast display line in doinbackground method. Keep e.printStackTrace as it is in catch block and check the logcat to see what error you have exactly on this line of code "androidHttpTransport.call(SOAP_ACTION, envelope);" – Rajen Raiyarela Jan 20 '15 at 07:50
  • 1
    Yes Farhan. Fatal exception was because of display toast in doinbackground, And exception at androidHttpTransport.call(SOAP_ACTION, envelope); line was java.net.sockettimeoutexception. For that you need to pass timeout around 60000 in HttpTransportSE. – UrMi Jan 20 '15 at 07:52
  • @UrMi how i can pass the timeout? – Farhan Shah Jan 20 '15 at 07:55
  • 1
    Pass it in HttpTransportSE. For Ex. in your code change this line: new HttpTransportSE(URL, 60000); – UrMi Jan 20 '15 at 07:58
  • dears the issue is still exist while i will remove the toast on doinbackground, when app is crashed,in the e.printstacktrace() the "java.net.SocketTimeoutException" will be display.. – Farhan Shah Jan 20 '15 at 07:58
  • @UrMi dear i think the issue is fix after passing the timeout,but i am not sure yet because this exception will be come after some time again.. – Farhan Shah Jan 20 '15 at 08:07

0 Answers0