0

i have tried to develop connecting mysql database via ksoap2 in android application.so am referred dis site:

http://codeoncloud.blogspot.in/2012/03/android-mysql-client.html

I am repeatedly getting "02-28 06:16:40.267: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol" in my application.

Dis is my android coding:

 package com.retailer.client;

 import android.app.Activity;
 import android.os.Bundle;
 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;

 public class RetailerActivity extends Activity {
 private static final String SOAP_ACTION = "retailer.com";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "retailer.com";
private static final String URL = "http://192.168.1.249:8085/Retailer/services/RetailerWS?wsdl";
/** 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);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);

  HttpTransportSE ht = new HttpTransportSE(URL);
 try {
 ht.call(SOAP_ACTION, envelope);
 SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
 SoapPrimitive s = response;
 String str = s.toString();
 String resultArr[] = str.split("&");//Result string will split & store in an array

 TextView tv = new TextView(this);

  for(int i = 0; i<resultArr.length;i++){
  tv.append(resultArr[i]+"\n\n");
  }
setContentView(tv);

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

Added internet permission on my manifest file also.

Then why blank screen only displayed on my emulator.. When am putting the site owner WSDL link means it is worked for me... But i putting my url means it is not worked for me..but site owner WSDL file and my WSDL file both are same only..i checked both files.Then y dis error dis came here.please guide me....

Krishna Veni
  • 2,217
  • 8
  • 27
  • 53

1 Answers1

0

The problem is that you are performing a network access on the main UI thread. Android 3.0 and above will crash your application (i.e. the system will throw a NetworkAccessOnMainThread exception) if you attempt to perform an HTTP request on the main thread. You need to wrap your HTTP request in an AsyncTask (or a Thread of some sorts) to ensure that you don't block the UI thread.

Read my blog post on the subject:

Why Ice Cream Sandwich Crashes Your App

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250