amine.touahria
amine.touahria

Reputation: 45

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

I'm trying to display a Listview by getting date from SOAP Web Service but every time i get an exception :

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

code :-

    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;
    }
}

Upvotes: 0

Views: 8335

Answers (1)

Gene
Gene

Reputation: 11267

Change this:

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

to

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

Upvotes: 1

Related Questions