Tanzeel Ahmed
Tanzeel Ahmed

Reputation: 81

Unfortunately Android WebService Has Stopped

i am new to android programming and have developed this app that takes in parameter in Kg's and converts it to grams using a web service but while running on emulator the app says "Unfortunately Android WebService Has Stopped" and the main problem in logcat being shown "cannot find org.ksoap2.serialization.SoapObjectare" though i have included the "ksoap2-android-assembly-2.5.4-jar-with-dependencies" jar file ... please help

This is my code:

package com.sencide;



private final String NAMESPACE = "http://www.webserviceX.NET/";
private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
private final String METHOD_NAME = "ConvertWeight";

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

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    String weight = "3700";
    String fromUnit = "Grams";
    String toUnit = "Kilograms";

    PropertyInfo weightProp =new PropertyInfo();
    weightProp.setName("Weight");
    weightProp.setValue(weight);
    weightProp.setType(double.class);
    request.addProperty(weightProp);

    PropertyInfo fromProp =new PropertyInfo();
    fromProp.setName("FromUnit");
    fromProp.setValue(fromUnit);
    fromProp.setType(String.class);
    request.addProperty(fromProp);

    PropertyInfo toProp =new PropertyInfo();
    toProp.setName("ToUnit");
    toProp.setValue(toUnit);
    toProp.setType(String.class);
    request.addProperty(toProp);

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

    try 
    {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        Log.i("myApp", response.toString());

        TextView tv = new TextView(this);
        tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
        setContentView(tv);

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

}

Upvotes: 0

Views: 1590

Answers (4)

Juan Hoyos
Juan Hoyos

Reputation: 1

I did as follows:

  1. Add the jar to the 'libs' folder and then add to the Build Path.
  2. Check the checkbox on kosoap2 library in Java Build Path options, Order And Export tab.

And the problem was solved.

Upvotes: 0

user2185726
user2185726

Reputation: 1

I did the same and solved the problem checking checkbox on kosoap2 library in Java Build Path options, Order And Export tab.

Upvotes: 0

Sana
Sana

Reputation: 9915

Add the jar to the 'libs' folder and NOT lib folder and then add to the Build Path.

Upvotes: 1

Cruceo
Cruceo

Reputation: 6834

Have you added the JAR to your Build Path?

From your package explorer, right click the JAR file and select: Build Path > Add to Build Path

Also, if you're just doing a simple conversion, why would you use a WebService? That could be done much quicker without connecting to the internet... Just my additional two cents

Upvotes: 0

Related Questions