java.lang.ClassCastException:org.ksoap2.serialization.SoapPrimitive? [英] java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive?

查看:125
本文介绍了java.lang.ClassCastException:org.ksoap2.serialization.SoapPrimitive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话是从我的Andr​​oid客户端应用程序的Web服务。得到响应,当我试图显示它我收到ClassCastException异常后。以下是我的code:

I am calling a web service from my android client application. After getting response when i am trying to display it i am getting ClassCastException. Following is my code:

public void onClick(View v) {
  setContentView(R.layout.report);
  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  EpcDetails epcdetails=new EpcDetails();
  epcdetails.setEpcId(input_val.getText().toString());

        request.addProperty("id", id
        SoapSerializationEnvelope sse=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        sse.setOutputSoapObject(request);

        sse.addMapping(NAMESPACE, 
        ProductDetailsRequest.ProductDetailsRequest.getSimpleName(),
        ProductDetailsRequest.ProductDetailsRequest);

        sse.implicitTypes=true;
        sse.setAddAdornments(false);
        AndroidHttpTransport aht=new AndroidHttpTransport(URL);

        try 
        {
         aht.call(SOAP_ACTION, sse);
         SoapObject response= (SoapObject) sse.getResponse();
         item_code.setText((CharSequence)(response.getProperty(6)));
         desc.setText((CharSequence) (response.getProperty(5)));
         price.setText(calc_price.toString());

        } catch (IOException e) 
        {
         e.printStackTrace();
        } catch (XmlPullParserException e)
        {
          e.printStackTrace();
       }

我得到异常的 ITEM_ code.setText((CharSequence的)(response.getProperty(6)));

12-20 19:26:12.864: ERROR/AndroidRuntime(811): FATAL EXCEPTION: main
12-20 19:26:12.864: ERROR/AndroidRuntime(811): java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at com.trueVUE.modules.report.MainSimulation.onClick(MainSimulation.java:123)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.view.View.performClick(View.java:2408)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.view.View$PerformClick.run(View.java:8816)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.os.Handler.handleCallback(Handler.java:587)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.os.Looper.loop(Looper.java:123)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at java.lang.reflect.Method.invokeNative(Native Method)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at java.lang.reflect.Method.invoke(Method.java:521)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-20 19:26:12.864: ERROR/AndroidRuntime(811):     at dalvik.system.NativeStart.main(Native Method)

请尽快提出了一些氛围中

Please suggest some soln ASAP.

问候,
拉胡尔

Regards, Rahul

推荐答案

由于您的web服务返回的类型为字符串,这样你就可以解决这个问题是这样的:

because the type of your webservice return is String ,so you can solve it this way:

Object  response=  sse.getResponse();  

当你的web服务的返回值类型为byte [],你可以做到这一点。

when your webservice return values type is byte[] ,you can do it

SoapObject response=(SoapObject)envelope.bodyIn;

这篇关于java.lang.ClassCastException:org.ksoap2.serialization.SoapPrimitive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆