我已经尝试了一段时间,但我无法得到正确的output.I面临从我的Android代码调用Web服务的问题。我的web service code返回一个字符串,其间带有分隔符“#”。现在我需要在Android的代码,将调用Web服务,使用复选框用户,使得实际名称显示分隔符选择Android代码调用Web服务给“应用程序意外停止”错误
这里是我的Android代码:
package com.sencide;
import java.net.SocketException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class TestApp extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/getData";
private static final String METHOD_NAME = "getData";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2/login2/Service1.asmx";
TextView tv;
boolean[] bln1=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.text1);
String[] arr2= call();
boolean[] bln = {false, false, false};
bln1 = new boolean[arr2.length];
new AlertDialog.Builder(TestApp.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle("Title")
.setMultiChoiceItems(arr2,
bln,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton,
boolean isChecked) {
if(isChecked){
bln1[whichButton] = true;
}
else{
bln1[whichButton] = false;
}
}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}
public String[] call()
{
SoapPrimitive responsesData = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
responsesData = (SoapPrimitive) envelope.getResponse();
System.out.println(" --- response ---- " + responsesData);
} catch (SocketException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" ----" + responsesData);
String serviceResponse= responsesData .toString();
String[] temp;
String delimiter = "#";
temp= serviceResponse.split(delimiter);
System.out.println(" ---- length ---- " + temp.length);
return temp;
}
}
请谁能帮助我解决我的问题,因为每次我运行代码我得到一个错误说“应用程序意外终止”
感谢
发布logcat错误 – Randroid
发布urcat应用程序的logcat消息 – Randroid