Reputation: 4553
I have accessed a web service from Android 2.2.It is perfectly OK.I changed my program for Android 4.0.3 to access same web service.But this doesn't work. Code of my Android program
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class AndroidWSClientActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.android4.com/";
private static final String METHOD_NAME = "sayHello";
private static final String NAMESPACE = "http://ws.android4.com/sayHello/";
private static final String URL = "http://175.157.45.91:8085/ForAndroid4/services/TestWs?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread networkThread = new Thread() {
@Override
public void run() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
final String str = response.toString();
runOnUiThread (new Runnable(){
public void run() {
TextView result;
result = (TextView)findViewById(R.id.textView1);
result.setText(str);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
}
}
I have added internet permission also. This program installing on emulator correctly. But doesn't show the result. No any errors showing.Eclipse says that "networkThread" is not used. How can I correct this ??
Thanks!
Upvotes: 1
Views: 1103
Reputation: 2667
It looks like you never started the networkThread. You would need this at the very end of your onCreate():
networkThread.start();
That being said, you would do well to use AsyncTask to do this type of thing. I think you will find it much easier once you get the hang of it.
http://developer.android.com/reference/android/os/AsyncTask.html
Upvotes: 1