Note that there are some explanatory texts on larger screens.

plurals
  1. POPass edittext value from android to web services
    primarykey
    data
    text
    <p>I want to pass edit text value from android to web services, but i can not do that every time it returns a null value. This is my simple web services.</p> <pre><code>package org.me.mongodb; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.ejb.Stateless; @WebService(serviceName = "Simple") @Stateless() public class Simple { public String testMyProps(@WebParam(name = "name")String fname){ return "First Name : "+fname; } } </code></pre> <p>and android code;</p> <pre><code>package com.prgguru.android; import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; 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; import com.example.webserviceactivity.R; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { private static final String SOAP_ACTION = ""; private static final String METHOD_NAME = "testMyProps"; private static final String NAMESPACE = "http://mongodb.me.org/"; private static final String URL = "http://10.0.2.2:8080/Simple/Simple?WSDL"; private String TAG = "PGGURU"; private static String barge=""; private static String info; Button b; TextView tv; EditText et; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); et = (EditText) findViewById(R.id.editText1); tv = (TextView) findViewById(R.id.tv_result); //Button to trigger web service invocation b = (Button) findViewById(R.id.button1); //Button Click Listener b.setOnClickListener(new OnClickListener() { public void onClick(View v) { //Check if barge text control is not empty if (et.getText().length() != 0 &amp;&amp; et.getText().toString() != "") { //Get the text control value barge = et.getText().toString(); //Create instance for AsyncCallWS AsyncCallWS task = new AsyncCallWS(); //Call execute task.execute(); //If text control is empty } else { tv.setText("Please enter Barge Name"); } } }); } public void testMyProps(String fname) { //Create request SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //Property which holds input parameters PropertyInfo getinfo = new PropertyInfo(); //Set Name getinfo.setName("arg0"); //Set Value getinfo.setValue(fname); //Set dataType getinfo.setType(String.class); //Add the property to request object request.addProperty(getinfo); //Create envelope SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; //Set output SOAP object envelope.setOutputSoapObject(request); //Create HTTP call object HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { //Invole web service androidHttpTransport.call(SOAP_ACTION, envelope); //Get the response SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); //Assign it to info static variable info = response.toString(); } catch (Exception e) { e.printStackTrace(); } } private class AsyncCallWS extends AsyncTask&lt;String, Void, Void&gt; { @Override protected Void doInBackground(String... params) { Log.i(TAG, "doInBackground"); testMyProps(barge); return null; } @Override protected void onPostExecute(Void result) { Log.i(TAG, "onPostExecute"); tv.setText(info); } @Override protected void onPreExecute() { Log.i(TAG, "onPreExecute"); tv.setText("Getting..."); } @Override protected void onProgressUpdate(Void... values) { Log.i(TAG, "onProgressUpdate"); } } } </code></pre> <p>It returns First name null;</p> <p>Please help i think i cannot pass the value to web services. Thanks a lot.</p> <p>Iam getting this error,</p> <pre><code>12-11 09:45:53.291: E/AndroidRuntime(1920): FATAL EXCEPTION: main 12-11 09:45:53.291: E/AndroidRuntime(1920): java.lang.IllegalStateException: Cannot execute task: the task is already running. 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:575) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.os.AsyncTask.execute(AsyncTask.java:534) 12-11 09:45:53.291: E/AndroidRuntime(1920): at com.prgguru.android.MainActivity$1.onClick(MainActivity.java:57) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.view.View.performClick(View.java:4240) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.view.View$PerformClick.run(View.java:17721) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.os.Handler.handleCallback(Handler.java:730) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.os.Handler.dispatchMessage(Handler.java:92) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.os.Looper.loop(Looper.java:137) 12-11 09:45:53.291: E/AndroidRuntime(1920): at android.app.ActivityThread.main(ActivityThread.java:5103) 12-11 09:45:53.291: E/AndroidRuntime(1920): at java.lang.reflect.Method.invokeNative(Native Method) 12-11 09:45:53.291: E/AndroidRuntime(1920): at java.lang.reflect.Method.invoke(Method.java:525) 12-11 09:45:53.291: E/AndroidRuntime(1920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 12-11 09:45:53.291: E/AndroidRuntime(1920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12-11 09:45:53.291: E/AndroidRuntime(1920): at dalvik.system.NativeStart.main(Native Method) 12-11 09:45:55.031: I/Process(1920): Sending signal. PID: 1920 SIG: 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload