org.ksoap2.serialization.SoapObject无法强制转换为org.ksoap2.serialization.SoapPrimitive

时间:2014-04-22 13:05:06

标签: java android serialization soap ksoap2

我尝试通过从SOAP Web服务获取日期来显示Listview,但每次出现异常时都会显示:

org.ksoap2.serialization.SoapObject cannot be cast to org.ksoap2.serialization.SoapPrimitive

代码: -

    public class ClientsReclamations extends Activity {
    public final String NAMESPACE = "http://tempuri.org/";
    public final String SOAP_ACTION = "http://tempuri.org/GetReclamations";
    public final String METHOD_NAME = "GetReclamations";

    ListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.clients_reclamations);
        lv=(ListView)findViewById(R.id.listViewRec);

        AsyncCallWS task = new AsyncCallWS();
        task.execute();
}

    public class AsyncCallWS extends AsyncTask<String, String,ArrayList>{
        ArrayList<Reclamation> resultats=new ArrayList<Reclamation>();
        protected void onPostExecute(ArrayList<Reclamation> resultats) {
             lv.setAdapter(new CustomListAdapterRec(getApplicationContext(), resultats));  
            super.onPostExecute(resultats);
        }
        protected ArrayList doInBackground(String... params) {

             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.dotNet = true;
             envelope.setOutputSoapObject(request);
             HttpTransportSE androidHttpTransport = new HttpTransportSE(getURL());
             try{
                 androidHttpTransport.call(SOAP_ACTION, envelope);
                 final SoapObject response = (SoapObject)envelope.getResponse();
                 Log.i("Liste Rec:----", response.toString());
                 runOnUiThread(new Runnable() {


                @Override
                 public void run() {
                 Reclamation reclamation;
                 SoapObject GetReclamationsResponse=new SoapObject();
                 SoapObject GetReclamationsResult=new SoapObject();
                 SoapObject Reclamations=new SoapObject();
                 SoapObject REC=new SoapObject();

                 GetReclamationsResponse=(SoapObject) response.getProperty(0);
                 GetReclamationsResult=(SoapObject) GetReclamationsResponse.getProperty(0);
                 Reclamations=(SoapObject) GetReclamationsResult.getProperty(0);
                 for(int i=0;i<Reclamations.getPropertyCount();i++){

                     REC=(SoapObject) Reclamations.getProperty("Reclamation");

                     SoapObject DateRec=new SoapObject();
                     SoapObject Objet=new SoapObject();
                     SoapObject Details=new SoapObject();
                     SoapObject Traitee=new SoapObject();

                     DateRec=(SoapObject) REC.getProperty("DateRec");
                     Objet=(SoapObject) REC.getProperty("Objet");
                     Details=(SoapObject) REC.getProperty("Details");
                     Traitee=(SoapObject) REC.getProperty("Traitee");

                     reclamation = new Reclamation();
                     reclamation.setDET_REC(Details.toString());
                     reclamation.setOBJET_REC(Objet.toString());
                     reclamation.setDate(DateRec.toString());
                     reclamation.setIcon(getResources().getDrawable(R.id.btn_yearly));
                     resultats.add(reclamation);
                     Log.i("Resultat Size : ------",resultats.size()+"");
                     }    


                }
           });


            }
            catch(Exception e){
             e.printStackTrace();

            }

            return resultats;

        }   

    }

    public void AfficheToast(){
        Toast t=Toast.makeText(this, "Aucune reclamation trouvée.", Toast.LENGTH_LONG);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
    }
    public String getURL()
    {
        String URL=null;
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        URL=sp.getString("serveur", "");
        return URL;
    }
}

1 个答案:

答案 0 :(得分:1)

改变这个:

final SoapObject response = (SoapObject)envelope.getResponse();

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();