gpt4 book ai didi

java - android ksoap2 崩溃,我无法捕捉到它

转载 作者:行者123 更新时间:2023-12-01 14:35:03 25 4
gpt4 key购买 nike

我正在关注这个tutorial 。它非常简单,我喜欢它,但它在模拟器上崩溃。我无法捕捉到错误。我不明白这个问题。这是一段代码。

private final String NAMESPACE = "http://www.webserviceX.NET/";
private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
private final String METHOD_NAME = "ConvertWeight";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

String weight = "3700";
String fromUnit = "Grams";
String toUnit = "Kilograms";


PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
request.addProperty(weightProp);

PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromUnit");
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
request.addProperty(fromProp);

PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToUnit");
toProp.setValue(toUnit);
toProp.setType(String.class);
request.addProperty(toProp);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());

TextView tv = new TextView(this);
tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
setContentView(tv);

} catch (Exception e) {
e.printStackTrace();
}

}

你认为问题出在哪里?我下载了 ksoap2 库并包含在项目中。我也在我的真实设备上尝试过并且有效。我还在配置文件上启用了互联网访问。

任何帮助都会很棒。或者你能推荐另一个教程吗?

最佳答案

Android 3.0之后无法在activity的主线程中访问web,需要启动新的线程来访问web

关于java - android ksoap2 崩溃,我无法捕捉到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16549915/

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