我创建了一个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 = "http://ws.retailer.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://ws.retailer.com";
private static final String URL = "http://10.0.0.55:8085/javaws/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();
}
}
}
但是当我调试它时出现: 05-24 17:46:26.031:D / SntpClient(71):请求时间失败:java.net.SocketException:协议不支持的地址族
如何清除..请指导我。
答案 0 :(得分:0)
您是否已将权限包含在AndroidManifest.xml中?
<uses-permission android:name="android.permission.INTERNET" />