Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:22:35+00:00 2026-06-05T10:22:35+00:00

I am new to android programming. Just wrote this code to convert kg’s to

  • 0

I am new to android programming. Just wrote this code to convert kg’s to grams through a web service. The program takes input from a user and returns the value in textbox but sadly I am not getting back any value. Please help.

package com.example.Passing;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


public class PassingActivity extends Activity
{
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. */

Button   mButton;
EditText mEdit;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mButton = (Button)findViewById(R.id.button);
    mEdit   = (EditText)findViewById(R.id.editText);

    mButton.setOnClickListener(

            new View.OnClickListener()
            {

                public void onClick(View view)
                {
                    String weight = mEdit.getText().toString();

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

                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


                    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());

                        EditText et = (EditText)findViewById(R.id.my_edit);
                        et.setText("equal"+response.toString());


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

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

The main.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number" >

    <requestFocus />
</EditText>

<EditText 
    android:layout_margin="20dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minLines="15"
    android:maxLines="15"
    android:textSize="12sp"
    android:editable="false"
    android:id="@+id/my_edit"/>


<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Convert" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:22:36+00:00Added an answer on June 5, 2026 at 10:22 am

    SoapPrimitive doesn’t always work fine. Try changing how you get the response for something like this: SoapObject result_xml = (SoapObject) envelope.bodyIn;

    instead of SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

    Edit:
    This is the code I used and worked perfectly (I used a Fragment but you can do the same in an Activity) but remember that any lenght operations (like internet since they can cause time outs or lags in network wich take more than 5s) must be done in a thread if you dont want to have unwanted side effects like the famous ANRs.

        public class TestFragment extends Fragment implements OnClickListener{
    
        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";
    
        private EditText textToConvert;
        private String weight;
        private Button send;
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            final View view = getView();
            textToConvert = (EditText) view.findViewById(R.id.ammount);
            send = (Button) view.findViewById(R.id.button);
            send.setOnClickListener(this);
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            return inflater.inflate( R.layout.main, container, false );
        }
    
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.button:
                weight = textToConvert.getText().toString();
                new AsyncSendData().execute();
                break;
            default:
                break;
            }
        }
    
    
        public class AsyncSendData extends AsyncTask<Void, Void, Void>{
    
            @Override
            protected Void doInBackground(Void... params) {
                String fromUnit = "Kilograms";
                String toUnit = "Grams";
    
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
                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);
                    SoapObject result_xml = (SoapObject) envelope.bodyIn;
                    Log.e("myApp", result_xml.toString());
                } 
                catch (Exception e){
                    e.printStackTrace();
                }
                return null;
            }
        }
    
    }
    

    and this is the layout I used:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="From" />
    
        <EditText
            android:id="@+id/ammount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" 
            android:inputType="number">
            <requestFocus />
        </EditText>
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
    </LinearLayout>
    

    so at the post execute method you can update your view…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have just started android programming, wrote a quick code, and havn't managed to
I'm new to Android programming and trying to wrap my head around this just
I'm fairly new to Android programming, so this may be a simple question, but
I'm very new to Android programming, so this is probably something pretty basic. I
I have just began opengl programming in android and i am fairly new to
Am new to android programming, just started learning it the past 6 weeks and
I'm new with Android programming. I'm just wondering whether its possible to set up
New to android programming. Getting Following error. 04-07 14:49:05.452: ERROR/AndroidRuntime(1566): FATAL EXCEPTION: main java.lang.OutOfMemoryError
I'm pretty new to Android programming so bear with me. I was wondering if
I am fairly new to Android programming and was wondering how I can get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.