I am trying to consume web service through android. I use ksoap2 library and follow this example. Whenever I enter data to text field, app crashes. I get the following error:
Process: com.tinyvoice.webservice, PID: 14447
java.lang.VerifyError: org/ksoap2/SoapEnvelope
at com.tinyvoice.webservice.WebServiceActivity$1.onClick(WebServiceActivity.java:49)
Here is the app from the link:
public class WebServiceActivity extends AppCompatActivity {
/**
* Called when the activity is first created.
*/
private static String SOAP_ACTION1 = "http://tempuri.org/FahrenheitToCelsius";
private static String SOAP_ACTION2 = "http://tempuri.org/CelsiusToFahrenheit";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME1 = "FahrenheitToCelsius";
private static String METHOD_NAME2 = "CelsiusToFahrenheit";
private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
Button btnFar, btnCel, btnClear;
EditText txtFar, txtCel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_service);
btnFar = (Button) findViewById(R.id.btnFar);
btnCel = (Button) findViewById(R.id.btnCel);
btnClear = (Button) findViewById(R.id.btnClear);
txtFar = (EditText) findViewById(R.id.txtFar);
txtCel = (EditText) findViewById(R.id.txtCel);
btnFar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
//Use this to add parameters
request.addProperty("Fahrenheit", txtFar.getText().toString());
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null) {
//Get the first property and change the label text
txtCel.setText(result.getProperty(0).toString());
} else {
Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
btnCel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//same logic for Farenheit
...
}
}
I am using Android Studio and added ksoap2.jar to libs folder and then added as a library. Thanks