简体   繁体   English

无法访问Android中的网络服务

[英]Not able to access web-service in Android

Not been able to access the webservice with a kinds of Android. 无法使用多种Android访问Web服务。 I am using Eclipse and ksoap2 library. 我正在使用Eclipse和ksoap2库。 I've tried all the codes circulating on the Internet. 我已经尝试了Internet上传播的所有代码。 Where is the error I'm doing. 我在做什么错误。 I installed everything again, but it did not help. 我再次安装了所有内容,但没有帮助。

Screenshot 屏幕截图

Error Logs 错误记录

08-25 11:32:51.872: E/Trace(972): error opening trace file: No such file or directory (2) 08-25 11:32:51.872:E / Trace(972):打开跟踪文件时出错:没有这样的文件或目录(2)

08-25 11:32:56.143: E/dalvikvm(972): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.knnklz.webservice04.MainActivity$2.run 08-25 11:32:56.143:E / dalvikvm(972):找不到方法com.knnklz.webservice04.MainActivity $ 2.run引用的类'org.ksoap2.serialization.SoapObject'

08-25 11:32:56.193: E/AndroidRuntime(972): FATAL EXCEPTION: Thread-93 08-25 11:32:56.193:E / AndroidRuntime(972):致命异常:Thread-93

08-25 11:32:56.193: E/AndroidRuntime(972): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject 08-25 11:32:56.193:E / AndroidRuntime(972):java.lang.NoClassDefFoundError:org.ksoap2.serialization.SoapObject

08-25 11:32:56.193: E/AndroidRuntime(972): at com.knnklz.webservice04.MainActivity$2.run(MainActivity.java:277) 08-25 11:32:56.193:E / AndroidRuntime(972):在com.knnklz.webservice04.MainActivity $ 2.run(MainActivity.java:277)

Android Java Code Android Java代码

tx = (TextView)findViewById(R.id.textView1);            

            try {
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                request.addProperty("Celsius", "85");
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

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


                androidHttpTransport.debug = true;
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

                tx.setText(response.toString());

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

There are only three reasons you will ever get this error: 出现此错误只有三个原因:

  1. The class genuinely doesn't exist. 该类确实不存在。 If you are using code from an official example and getting this, make sure you have the latest build of the library 如果您使用的是官方示例中的代码并获取该代码,请确保您具有该库的最新版本
  2. You have not added the jar to your build path. 您尚未将jar添加到构建路径。 To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path. 要解决此问题,请在Eclipse中的jar上单击鼠标右键,然后执行“构建路径”►“添加到构建路径”。
  3. Your jar is not in the /libs folder. 您的jar不在/ libs文件夹中。 This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. 当您将jar添加到构建路径中时,就会发生这种情况,但是较新版本的ADT需要将其放在/ libs中。 Put it there and re-add it to the build path. 将其放在此处并将其重新添加到构建路径。

Create a folder named " libs " in the project directory and copying all the external jar files there. 在项目目录中创建一个名为“ libs ”的文件夹,并将所有外部jar文件复制到该目录中。

Make sure you have added the ksoap library to the Build Path by by right clicking on the jar file and " Add it to build " 通过右键单击jar文件,然后单击“ 添加以构建 ”,确保已将ksoap库添加到构建路径。

Plus make sure you are using the latest version of the ksoap library. 另外,请确保您使用的是ksoap库的最新版本。 Direct download link . 直接下载链接

I removed the following line, and improved. 我删除了以下行,并进行了改进。

File: AndroidManifest.xml 档案: AndroidManifest.xml

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM