0

我试图在android应用程序中通过ksoap2开发连接mysql数据库。所以我提到了dis站点:

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

我在我的应用程序中反复收到“02-28 06:16:40.267: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol”。

Dis是我的android编码:

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

还为我的清单文件添加了 Internet 权限。

那为什么空白屏幕只显示在我的模拟器上..当我放置站点所有者 WSDL 链接时意味着它对我有用......但是我输入我的 url 意味着它对我不起作用..但是站点所有者 WSDL 文件和我的 WSDL文件都相同而已..我检查了这两个文件。然后y dis error dis来了。请指导我....

4

1 回答 1

0

问题是您正在主 UI 线程上执行网络访问。NetworkAccessOnMainThread如果您尝试在主线程上执行 HTTP 请求,Android 3.0 及更高版本将使您的应用程序崩溃(即系统将抛出异常)。您需要将您的 HTTP 请求包装在一个AsyncTask(或Thread某种类型的)中,以确保您不会阻塞 UI 线程。

阅读我关于该主题的博客文章:

为什么冰淇淋三明治会使您的应用程序崩溃

于 2012-06-28T04:41:41.660 回答