我在php中有一个Web服务,它从数据库中检索数据,并在我的Android应用程序中使用这个Web服务。问题是我需要在另一个android活动中检索的数据,我尝试使用for循环从kvm序列化中检索数据并将其保存在数组中并使用意图将数组发送到另一个活动。我遇到了以下问题
03-28 17:48:37.629: E/AndroidRuntime(956): FATAL EXCEPTION: main
03-28 17:48:37.629: E/AndroidRuntime(956): java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive cannot be cast to java.lang.String
03-28 17:48:37.629: E/AndroidRuntime(956): at com.example.testwebser.MainActivity$1.onClick(MainActivity.java:87)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.view.View.performClick(View.java:4204)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.view.View$PerformClick.run(View.java:17355)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.os.Handler.handleCallback(Handler.java:725)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.os.Looper.loop(Looper.java:137)
03-28 17:48:37.629: E/AndroidRuntime(956): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-28 17:48:37.629: E/AndroidRuntime(956): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 17:48:37.629: E/AndroidRuntime(956): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 17:48:37.629: E/AndroidRuntime(956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 17:48:37.629: E/AndroidRuntime(956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 17:48:37.629: E/AndroidRuntime(956): at dalvik.system.NativeStart.main(Native Method)
第87行给出了错误,即
myArr[i]= (String) ks.getProperty(i);
这是我主要活动的一部分 试试{
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("response: " + androidHttpTransport.responseDump);
SoapObject result = (SoapObject)envelope.getResponse();
KvmSerializable ks = (KvmSerializable)envelope.getResponse();
if(result!=null){
String[] myArr=new String[7];
for(int i=0;i<ks.getPropertyCount();i++)
{
myArr[i]= (String) ks.getProperty(i);
}
Intent intent = new Intent(MainActivity.this, View_menu.class);
intent.putExtra("menu", myArr);
startActivity(intent);
}
我不知道如何检索data.please help:)
答案 0 :(得分:0)
我已经能够通过在我的主要活动
中使用以下代码来解决它Bundle basket = new Bundle();
basket.putString("mname",mname);
basket.putString("mdesc", mdesc);
basket.putString("mprice", mprice);
basket.putString("mtime", mtime);
basket.putString("mavail", mavail);
basket.putString("mpromo", mpromo);
Intent goToViewMenu = new Intent(MainActivity.this, View_menu.class);
goToViewMenu.putExtras(basket);
startActivity(goToViewMenu);
并在显示类中检索
if(bundle !=null)
{
String strdata = bundle.getString("mname");
String strdata1 = bundle.getString("mdesc");
txt_name.setText(strdata);
}
else
{
}
}