DEBUG / SntpClient(71):请求时间失败:java.net.SocketException

时间:2012-06-25 13:34:27

标签: android mysql web-services ksoap2

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

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

我反复得到“02-28 06:16:40.267:DEBUG / SntpClient(66): 请求时间失败:java.net.SocketException:地址族不是 协议支持“在我的应用程序中。

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

我的清单文件也增加了互联网权限。

那么为什么空白屏幕只显示在我的模拟器上.. 什么时候把网站所有者WSDL链接意味着它对我有用... 但我把我的网址意味着它不适合我..但网站所有者WSDL文件和我的WSDL文件都是相同的..我检查了两个文件。然后我的错误消息来到这里。请指导我.... < / p>

1 个答案:

答案 0 :(得分:0)

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

阅读我关于这个主题的博文:

Why Ice Cream Sandwich Crashes Your App