Android SOAP示例程序报错

标签 android soap

Android SOAP 示例程序错误

如何纠正这个错误。请帮助我

主.java

public class Main extends Activity {

private static String SOAP_ACTION = "http://tempuri.org/HelloWorld";

private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "HelloWorld";

private static String URL = "http://sygnetinfosol.com/webservice.asmx";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Initialize soap request + add parameters
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
    request.addProperty("Parameter","Value");


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);

    // Make the soap call.
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {

        //this is the actual part that will call the webservice
        androidHttpTransport.call(SOAP_ACTION, envelope);        
    } catch (Exception e) {
        e.printStackTrace(); 
    } 

    // Get the SoapResult from the envelope body.       
    SoapObject result = (SoapObject)envelope.bodyIn;

    if(result != null){
        TextView t = (TextView)this.findViewById(R.id.resultbox);
        t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
    }

}
}

日志错误

03-11 07:07:07.320: E/AndroidRuntime(908): FATAL EXCEPTION: main
03-11 07:07:07.320: E/AndroidRuntime(908): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
03-11 07:07:07.320: E/AndroidRuntime(908):  at com.pxr.tutorial.soap.weather.Main.onCreate(Main.java:29)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.Activity.performCreate(Activity.java:5104)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.os.Looper.loop(Looper.java:137)
03-11 07:07:07.320: E/AndroidRuntime(908):  at android.app.ActivityThread.main(ActivityThread.java:5041)
03-11 07:07:07.320: E/AndroidRuntime(908):  at java.lang.reflect.Method.invokeNative(Native Method)
03-11 07:07:07.320: E/AndroidRuntime(908):  at java.lang.reflect.Method.invoke(Method.java:511)
03-11 07:07:07.320: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-11 07:07:07.320: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-11 07:07:07.320: E/AndroidRuntime(908):  at dalvik.system.NativeStart.main(Native Method)

最佳答案

ksoap2-android-assembly-2.6.2-jar-with-dependencies.jar

放在/libs 文件夹下,这样 Eclipse ADT 会自动将您的 jar 添加到应用程序的构建路径中。

下载 ksoap。 jar 。放在libs文件夹下。右键单击项目。转到属性。转到 java 构建路径。单击添加 jar 。将 ksaop jar 文件从 lib 文件夹添加到您的项目。

清理并构建项目。这应该对你有帮助。

编辑1

右键单击“项目”-> 属性-> Java 构建路径-> 订购和导出 enter image description here

现在,确保您已经“检查”了外部添加的“jar”文件,正如您在快照中看到的那样。 确保该外部 jar 文件的顺序也与 snap 中显示的顺序相同。

关于Android SOAP示例程序报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15333243/

相关文章:

java - CXF:如何拦截 SOAP 响应

.net - WSDL.exe - 生成接口(interface)和具体类以便以后轻松伪造/模拟

php - 如何将 PHP5 SoapClient::SoapClient() 与客户端证书一起使用?

android - adb 今天无法连接到 VirtualBox 中的 Android-x86

android - 创建客户端 ID : "An unexpected error has occurred. We' re looking into it. 时“

java - 如何用java编写soap客户端?

javascript - 使用 VBScript 的 SOAP POST 请求

android - android中大小写敏感

android - 如何使用谷歌应用引擎从安卓设备访问本地主机?

android - 无法以编程方式更改 TextInputLayout 提示重力