我是Android编程新手并开发了这个应用程序,它接受Kg中的参数并使用Web服务将其转换为克但在模拟器上运行时应用程序显示“不幸的是Android WebService已停止”以及logcat中的主要问题被显示“找不到org.ksoap2.serialization.SoapObjectare”虽然我已经包含了“ksoap2-android-assembly-2.5.4-jar-with-dependencies”jar文件...请帮忙
这是我的代码:
package com.sencide;
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";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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();
}
}
}
答案 0 :(得分:1)
将jar添加到'libs'文件夹而不是lib文件夹,然后添加到Build Path。
答案 1 :(得分:0)
您是否已将JAR添加到构建路径?
在您的包浏览器中,右键单击JAR文件并选择:Build Path>添加到构建路径
另外,如果您只是进行简单的转换,为什么要使用WebService?没有连接到互联网,这可以更快地完成...只是我的额外两美分
答案 2 :(得分:0)
我做了同样的事情并解决了Java Build Path选项,Order and Export选项卡中kosoap2库上的问题检查复选框。
答案 3 :(得分:0)
我做了如下:
问题解决了。