简体   繁体   中英

httpTransport.call(SOAP_ACTION, envelope); Throwing null exception Android

I get this error when using breakpoint and it went into catch exception.

httpTransport.call(SOAP_ACTION, envelope);

Is it that httpTransport connection should not be null ?

    public class MainActivity extends Activity {

TextView tv;

SoapObject request;

SoapSerializationEnvelope envelope;

HttpTransportSE androidHttpTransport;

Object result;

public String METHOD_NAME = "sum";

public String NAMESPACE = "http://ws.calculatorJava.org";

// private String SOAP_ACTION = NAMESPACE + METHOD_NAME;

public String SOAP_ACTION = "http://ws.calculatorJava.org/sum";

public static final String URL = "http://172.168.1.2:8888/CalculatotJava/services

    /Calculate.wsdl";


/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    tv = (TextView) findViewById(R.id.textView1);

    try {

        request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("i", 5);

        request.addProperty("j", 15);

        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        androidHttpTransport = new HttpTransportSE(URL);

        Toast.makeText(getBaseContext(), "GET", Toast.LENGTH_LONG).show();

        androidHttpTransport.call(SOAP_ACTION, envelope);

        result = envelope.getResponse();

        Toast.makeText(getBaseContext(),

                "  Result " + "\n" + result.toString(), 

                        Toast.LENGTH_SHORT)

                .show();

        // System.out.println("Result : " + result.toString());

        tv.setText("Addition : " + result.toString());

    } catch (Exception E) {

        E.printStackTrace();

        tv.setText("ERROR  " + "\n" + E.getClass().getName() + ":"

                + E.getMessage());

    }

}

 }

Your androidHttpTransport.call(SOAP_ACTION, envelope); is probably failing because you are calling this on the main UI thread. Try lowering the SDK version in your manifest to 8/9 or put your whole soap request code inside an AsyncTask or different thread.

如果您的gettint networkonmain异常,请记住始终在Android异步任务中执行与网络相关的任务,然后在主线程中调用异步任务

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM