2

Here is my class which is calling the SOAP. I'm getting the following error and I don't understand why.

ava.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.ksoap2.serialization.SoapPrimitive.toString()' on a null object reference

public class WebServicesController {

private static final String NAMESPACE = "http://mywebsite.com:9000/";
private static final String ASMXURL = "Services.asmx?";

private String TAG = "PGGURU";
static SoapPrimitive resultString;

public static void SoapActionExecuteStoredProcedure(String METHOD_NAME,List<String> ArgumentPipeValue) throws XmlPullParserException, IOException {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    //add arguments in to
    for (String arg : ArgumentPipeValue) {
        String[] splitArgs = arg.split("|");
        request.addProperty(splitArgs[0], splitArgs[1]);
    }
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject (request);
    envelope.dotNet  = true;
    HttpTransportSE ht = new HttpTransportSE(NAMESPACE+ASMXURL);


    ht.call (METHOD_NAME, envelope);
    SoapObject response = (SoapObject)envelope.getResponse();
    String result = response.getProperty(0).toString();

}
}

And here is how I call it.

  bt.setOnClickListener( new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.i(TAG, "doInBackground");
            List<String> myargs = new ArrayList<String>();
            myargs.add("_caseId|apples");
            try {
                WebServicesController.SoapActionExecuteStoredProcedure("DJProvider_Delete", myargs);
            } catch (Exception e) {
            }
        }
    });

Any pointers would be fantastic. It could be I don't completely understand how to use KSoap, but i've followed a few tutorials and I keep getting this error.

JL1
  • 309
  • 2
  • 18

2 Answers2

1

I think you are getting error on this line

**String result = response.getProperty(0).toString();**

If that's the case please check whether you are getting any response at all. If you are getting no response at all, then that could be the reason.

check if you are providing the arguments to the webservice correctly. When using SOAP you have to provide arguments in a particular structure, like a SOAP object inside another SOAP object. Check the SOAP object you are creating and the one required are the same. (Just print the request.toString() for checking)

PS: I meant to put this in the comment section. But i dont have enough reputation.

Akhil Soman
  • 2,077
  • 2
  • 17
  • 30
0

i faced this issue recently, the problem was about internet permission, and i fixed it by adding this line of code into manifest file.

<uses-permission android:name="android.permission.INTERNET" />
Mahdi Rashidi
  • 1,359
  • 3
  • 18
  • 33