gpt4 book ai didi

java - httpTransport.call(SOAP_ACTION,信封);引发null异常Android

转载 作者:行者123 更新时间:2023-12-03 08:58:30 26 4
gpt4 key购买 nike

使用断点时出现此错误,并且进入catch异常。
httpTransport.call(SOAP_ACTION, envelope);
httpTransport连接不应该是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());

}

}

}

最佳答案

您的androidHttpTransport.call(SOAP_ACTION, envelope);可能失败,因为您正在主UI线程上调用它。尝试将 list 中的SDK版本降低到8/9,或将整个肥皂请求代码放入AsyncTask或其他线程中。

关于java - httpTransport.call(SOAP_ACTION,信封);引发null异常Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15679095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com