java - ksoap2 序列化错误

标签 java android web-services soap ksoap2

我尝试制作一个简单的应用程序来获取网络服务的字符串,我已经下载了 ksopa2 软件包,制作精良,数据正确(在互联网教程上测试过),我收到以下错误,您可以,您知道那可能是吗?非常感谢!

应用:

public class MainActivity extends Activity { 

private static final String SOAP_ACTION = "http://tempuri.org/devuelveString"; //Variables
private static final String METHOD_NAME = "devuelveString";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:52335/Service1.asmx";

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

    Button boton = (Button) findViewById(R.id.Bboton);

    boton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            InvocarWs(); //call the method

        }
    });
}

public void InvocarWs() {
    System.out.println("llama al metodo");
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11); // utilizar la version que
                                        // corresponda:11 o 12
        envelope.dotNet = true; // para WS ASMX, sólo si fue construido con
                                // .Net
        envelope.setOutputSoapObject(request);

        HttpTransportSE transporte = new HttpTransportSE(URL);

        transporte.call(SOAP_ACTION, envelope);

        SoapPrimitive resultado = (SoapPrimitive) envelope.getResponse();

        System.out.println("" + resultado.toString());

    } catch (Exception e) {
        System.out.println("catch");
    }
}

}

错误日志vcat

04-26 08:03:08.731: E/AndroidRuntime(536): FATAL EXCEPTION: main
04-26 08:03:08.731: E/AndroidRuntime(536): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.example.prueba.Conexion.InvocarWs(Conexion.java:24)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.example.prueba.MainActivity$1.onClick(MainActivity.java:25)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.view.View.performClick(View.java:2485)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.view.View$PerformClick.run(View.java:9080)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Handler.handleCallback(Handler.java:587)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Looper.loop(Looper.java:123)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-26 08:03:08.731: E/AndroidRuntime(536):  at java.lang.reflect.Method.invokeNative(Native Method)
04-26 08:03:08.731: E/AndroidRuntime(536):  at java.lang.reflect.Method.invoke(Method.java:507)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-26 08:03:08.731: E/AndroidRuntime(536):  at dalvik.system.NativeStart.main(Native Method)

最佳答案

您需要将 jar 复制到项目中的 libs 目录中。 ADK 从该文件夹中选取库并将它们转换为针对 Dalvik 优化的类。

Creating a folder "libs" in the project
Copying the external jars in to the folder
Refresh the folder
Go to properties -> Build path -> Add Jar (not external JAR)
Clean the project
Restart Eclipse

也试试这个,

Go to the Order and Export tab on the same popup window
Check the box against the newly added jar

关于java - ksoap2 序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16231735/

相关文章:

java - 读取 Asta/Power 项目时出错

android - 无法在 android 中播放超过 7 次的声音

java - 非法参数异常 : ProtectionToken is not a <wsp:Policy> element

c# - 我是否应该将主版本号放入 C#/Java 命名空间?

Java:第二个窗口是空白的

java - 计算随机生成的数字列表中的频率

java - 通知 onClick 到其他 fragment

c# - Azure 网络作业 : C# - The Autodiscover service couldn't be located error

java - 如何在数组中同时调用抽象方法和接口(interface)方法?

android - 在 LinearLayout 中设置 TextView 的宽度