0

我在 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);
                }

我不知道如何检索数据。请帮助:)

4

1 回答 1

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
         {

         }
    }
于 2013-03-29T09:58:26.127 回答