Search code examples
javaandroidandroid-studiosoapksoap2

'int org.ksoap2.serialization.KvmSerializable.getPropertyCount()' on a null object reference


i know the condition when i m getting this exception when i am connected to internet but internet is not in service so that time my request goes to on server but i m not able to handle that respond.. after that i am getting this exception.

//I am getting NullPointerException on response= envelope.getResponse();

class Logintask extends AsyncTask<String, String, String> {


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            setmainloader(1);

        }

        @Override
        protected String doInBackground(String... args) {

            String NAMESPACE = "URL";
            String URL = "API Call";
            String SOAP_ACTION = "Validate user api";
            String METHOD_NAME = "Some method";

            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);


            Request.addProperty("TokenID", sm.getUserDetails().get(SessionManager.TOKEN_ID));



            Request.addProperty("UserName", enteredusername);
            Request.addProperty("Pwd", enteredpassword);
            Request.addProperty("GCMID", " ");
            Request.addProperty("Imei", imei);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(Request);
            HttpTransportSE httpTransport = new HttpTransportSE(URL, 20000);

            try {
                httpTransport.call(SOAP_ACTION, envelope);

            } catch (SocketTimeoutException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {


                //CHECK FOR RESPONSE


                Log.d("check for response", "doInBackground: ");

//i am getting exception here ???? when i am getting this response when //connected no wifi or mobile data but internet is not coming.

            response=envelope.getResponse();



            //  Log.d("response",response.toString());

        } catch (SoapFault e) {
            // TODO Auto-generated catch block
        }

        return null;
    }

here is my log below

FATAL EXCEPTION: AsyncTask #6 Process: com.virtuzoconsultancyservicespvtltd.attendenceapp, PID: 13903 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int org.ksoap2.serialization.KvmSerializable.getPropertyCount()' on a null object reference at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:521) at com.vcpl.attendenceappnew.EmailDialog$mailattendance.doInBackground(EmailDialog.java:224) at com.vcpl.attendenceappnew.EmailDialog$mailattendance.doInBackground(EmailDialog.java:175) at android.os.AsyncTask$2.call(AsyncTask.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)  at java.lang.Thread.run(Thread.java:818)


Solution

  • Change this

     response=envelope.getResponse();
    

    to this

    SoapPrimitive response = (SoapPrimitive) envelope.getResponse();