Why is my application crashing when I try to publish data in a Web service?

advertisements

what i am doing is that i am trying to send some strings from my activity and post to a web service .. my code is like this :

approve.setOnClickListener(new OnClickListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
//              Intent intent=new Intent(Info.this,MainActivity.class);

                 status="1";
                 ordernumber="25";
                 userid="11";
                 //Create instance for AsyncCallWS
                AsyncCallWS task = new AsyncCallWS();
                //Call execute
                task.execute();
            }
        });

     private class AsyncCallWS extends AsyncTask {

        @Override
        protected Object doInBackground(Object... params) {
            // TODO Auto-generated method stub

                loginStatus = WebService.invokeLoginWS(status,ordernumber,userid,"GetOrderData");
                return null;
            }

            protected void onPostExecute(Void result) {
                //Make Progress Bar invisible
                webservicePG.setVisibility(View.INVISIBLE);
                Intent intObj = new Intent(Info.this,PenddingOrders.class);
                //Error status is false
            }

            //Make Progress Bar visible
            protected void onPreExecute() {
                webservicePG.setVisibility(View.VISIBLE);
            }

        }

and here is my web service class like this :

package post;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class WebService {
    //Namespace of the Webservice - can be found in WSDL
    private static String NAMESPACE = "http://service.programmerguru.com/";
    //Webservice URL - WSDL File location
    private static String URL = "http://192.168.1.113/testOrder/OrderAndroid.asmx";//Make sure you changed IP address
    //SOAP Action URI again Namespace + Web method name
    private static String SOAP_ACTION = "http://service.programmerguru.com/";

    public static boolean invokeLoginWS(String status,String orderid,String username, String webMethName) {
        boolean loginStatus = false;
        // Create request
        SoapObject request = new SoapObject(NAMESPACE, webMethName);
        // Property which holds input parameters
        PropertyInfo statusPI = new PropertyInfo();
        PropertyInfo orderidPI = new PropertyInfo();
        PropertyInfo usernamePI = new PropertyInfo();
        // Set Username
        statusPI.setName("status");
        // Set Value
        statusPI.setValue(status);
        // Set dataType
        statusPI.setType(String.class);
        // Add the property to request object
        request.addProperty(statusPI);
        //Set Password
        orderidPI.setName("orderid");
        //Set dataType
        orderidPI.setValue(orderid);
        //Set dataType
        orderidPI.setType(String.class);
        //Add the property to request object
        request.addProperty(orderidPI);
        usernamePI.setName("username");
        //Set dataType
        usernamePI.setValue(username);
        //Set dataType
        usernamePI.setType(String.class);
        //Add the property to request object
        request.addProperty(usernamePI);

        // Create envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
            // Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            // Assign it to  boolean variable variable
            loginStatus = Boolean.parseBoolean(response.toString());

        } catch (Exception e) {
            //Assign Error Status true in static variable 'errored'

            e.printStackTrace();
        }
        //Return booleam to calling object
        return loginStatus;
    }
}

and my activity crash when i press the approve button and here are some of what i see in the logcat:

FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.newmaamoontest.Info$AsyncCallWS.onPreExecute(Info.java:151)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)


Your are not initializing webservicePG view variable. You are trying to call method without instantiating object. try initializing and instantiate webservicePG in onCreate method using webservicePG = findViewById(R.id.your_id); or if you are creating dynamically webservicePG = new View(this);