我正在尝试测试为我制作的网络服务,当我尝试使用 android 时,我遇到了问题。我阅读了所有帖子,但无法解决。这是我的代码:
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
import android.widget.TextView;
import android.os.Bundle;
import android.app.Activity;
public class ListIncidencesActivity extends Activity {
private static final String NAMESPACE = "http://localhost:8080/";
private static String URL="http://localhost:8080/WebApp/services/Hola?wsdl";
private static final String METHOD_NAME = "DiHola";
private static final String SOAP_ACTION ="http://localhost:8080/DiHola";
private SoapObject request=null;
private SoapSerializationEnvelope envelope=null;
private SoapPrimitive resultsRequestSOAP=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_incidences);
request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("nombre","R1K4R2");
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE transporte = new HttpTransportSE(URL);
try {
transporte.call(SOAP_ACTION, envelope);
resultsRequestSOAP = (SoapPrimitive)envelope.getResponse();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v("Milagro?","SIIII "+ resultsRequestSOAP);
}
}
当我添加库ksoap2-android-assembly-2.5.8-jar-with-dependencies
时,运行时出现致命错误:
01-25 04:46:38.374: E/AndroidRuntime(781): FATAL EXCEPTION: main
01-25 04:46:38.374: E/AndroidRuntime(781): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
01-25 04:46:38.374: E/AndroidRuntime(781): at es.proyecto.gestorincidencias.ListIncidencesActivity.onCreate(ListIncidencesActivity.java:47)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.Activity.performCreate(Activity.java:5008)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.os.Looper.loop(Looper.java:137)
01-25 04:46:38.374: E/AndroidRuntime(781): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-25 04:46:38.374: E/AndroidRuntime(781): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 04:46:38.374: E/AndroidRuntime(781): at java.lang.reflect.Method.invoke(Method.java:511)
01-25 04:46:38.374: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-25 04:46:38.374: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-25 04:46:38.374: E/AndroidRuntime(781): at dalvik.system.NativeStart.main(Native Method)
如果我更新到ksoap2-android-assembly-2.6.5-jar-with-dependencies
我会遇到编译问题:
The import org.ksoap2 cannot be resolved
但与我没有添加任何人(电线)时不同。出现一个!mi 图标项目中的信号。
所以有什么想法吗??我希望这是一个我看不到的小错误,因为我没有经验,这是我的第一次。
提前致谢。