Android 使用ksoap通过web服务调用传递字符串生成警告
我已经实现了一个调用soapweb服务的Android代码。web服务采用“abc#bcd#efg#”形式的字符串参数。当我传递这样一个字符串时,会收到如下警告: 请注意: ArrayList items2=新的ArrayList()强> 从logcat:Android 使用ksoap通过web服务调用传递字符串生成警告,android,web-services,ksoap2,android-ksoap2,Android,Web Services,Ksoap2,Android Ksoap2,我已经实现了一个调用soapweb服务的Android代码。web服务采用“abc#bcd#efg#”形式的字符串参数。当我传递这样一个字符串时,会收到如下警告: 请注意: ArrayList items2=新的ArrayList() 从logcat: 11-15 17:44:35.511: INFO/System.out(304): arr2 is ann 11-15 17:44:35.511: INFO/System.out(304): [ann] 11-15 17:44:
11-15 17:44:35.511: INFO/System.out(304): arr2 is ann
11-15 17:44:35.511: INFO/System.out(304): [ann]
11-15 17:44:35.511: INFO/System.out(304): absent students are
11-15 17:44:35.511: INFO/System.out(304): ann#
11-15 17:44:35.511: INFO/System.out(304): arr2 is john
11-15 17:44:35.511: INFO/System.out(304): [ann, john]
11-15 17:44:35.521: INFO/System.out(304): absent students are
11-15 17:44:35.521: INFO/System.out(304): ann#john#
11-15 17:44:35.521: DEBUG/(304): items:
11-15 17:44:35.521: DEBUG/string is(304): ann
11-15 17:44:35.521: DEBUG/string is(304): john
11-15 17:44:37.121: WARN/System.err(304): java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
11-15 17:44:37.121: WARN/System.err(304): at com.example.display.call2(display.java:237)
11-15 17:44:37.133: WARN/System.err(304): at com.example.display$3.onClick(display.java:196)
11-15 17:44:37.133: WARN/System.err(304): at android.view.View.performClick(View.java:2408)
11-15 17:44:37.133: WARN/System.err(304): at android.view.View$PerformClick.run(View.java:8816)
11-15 17:44:37.133: WARN/System.err(304): at android.os.Handler.handleCallback(Handler.java:587)
11-15 17:44:37.133: WARN/System.err(304): at android.os.Handler.dispatchMessage(Handler.java:92)
11-15 17:44:37.133: WARN/System.err(304): at android.os.Looper.loop(Looper.java:123)
11-15 17:44:37.133: WARN/System.err(304): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-15 17:44:37.151: INFO/System.out(304): A is
由于这个原因,应用程序运行,但我仍然没有得到预期的响应
我的Android代码:
//Button code to insert checkbox value
alertDialog.setNegativeButton("Mark absent", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
final Button markabsent = (Button) findViewById(R.id.Button02);
markabsent.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Toast.makeText(display.this,"You have marked the students absent",Toast.LENGTH_SHORT).show();
SparseBooleanArray checkedabsent = lView.getCheckedItemPositions();
for (int i = 0; i < arr2.length; i++)
{
if (checkedabsent.get(i))
{
System.out.println("arr2 is "+arr2[i]);
items2.add(arr2[i]);
System.out.println(items2);
s.append(arr2[i] + "#");
x=s.toString();
//s.deleteCharAt(s.length()-1);
System.out.println("absent students are\n" +s);
}
}
Log.d("", "items:");
for (String string : items2)
{
Log.d("string is", string);
}
}
});
}
});
alertDialog.show();
//Button to call web service
final Button submit = (Button) findViewById(R.id.Button03);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
// Perform action on click
Toast.makeText(display.this,"You have selected to submit data of students",Toast.LENGTH_SHORT).show();
ProgressDialog dialog = new ProgressDialog(display.this);
String a=call2(x);
System.out.println("A is "+a);
dialog.setMessage("Submitting data...");
dialog.show();
if(a.equalsIgnoreCase("success"))
startActivity(new Intent(display.this,End.class));
}
});
}
//web service calling method ksoap used
public String call2(String x)
{
String b="";
SoapObject request = new SoapObject(namespace, method_NAME);
request.addProperty("names",x.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport android = new AndroidHttpTransport(url);
android.debug = true;
try
{
android.call(soap_ACTION, envelope);
SoapPrimitive res = (SoapPrimitive) envelope.getResponse();
SoapObject result = (SoapObject)envelope.getResponse();
Log.i("myapp",result.toString());
System.out.println(" --- response ---- " + res);
b=result.toString();
} catch (SocketException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
请帮我解决这个问题。谢谢选择其中一个
SoapPrimitive res = (SoapPrimitive) envelope.getResponse();
或
不是两个都是选择其中一个
SoapPrimitive res = (SoapPrimitive) envelope.getResponse();
或
不是两个都是我认为错误在(第236行)中
如果是,则尝试使用此解决方案:-
SoapObject result = (SoapObject)envelope.bodyIn;
我认为错误在(第236行)中
如果是,则尝试使用此解决方案:-
SoapObject result = (SoapObject)envelope.bodyIn;
fine选择了第二个,仍然是相同的问题fine选择了第二个,仍然是相同的问题我认为您应该更改这一行
request.addProperty(“names”,x.toString())代码>到请求.addProperty(“名称”,x)代码>。尝试此操作,然后询问问题是否仍然存在。我已更改它。问题仍然存在existing@Shashank_Itmaster:我正在使用ksoap版本2.5.4您可以在post中粘贴wsdl吗?做一件事,使用HttpTransportSE
而不是AndroidHttpTransport
@shashashank_Itmaster:我认为您应该更改这一行request.addProperty(“name”,x.toString())代码>到请求.addProperty(“名称”,x)代码>。尝试此操作,然后询问问题是否仍然存在。我已更改它。问题仍然存在existing@Shashank_Itmaster:我正在使用ksoap版本2.5.4您可以在post中粘贴wsdl吗?使用httptransport
代替AndroidHttpTransport
@shashashank\u Itmaster做一件事:
SoapObject result = (SoapObject)envelope.bodyIn;