简体   繁体   中英

Not able to access web-service in Android

Not been able to access the webservice with a kinds of Android. I am using Eclipse and ksoap2 library. I've tried all the codes circulating on the 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: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.193: E/AndroidRuntime(972): FATAL EXCEPTION: 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): at com.knnklz.webservice04.MainActivity$2.run(MainActivity.java:277)

Android Java Code

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. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path.
  3. Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /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.

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 "

Plus make sure you are using the latest version of the ksoap library. Direct download link .

I removed the following line, and improved.

File: AndroidManifest.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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