java - org.ksoap2.serialization.SoapObject 无法转换为 org.ksoap2.serialization.SoapPrimitive

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

最佳答案

更改此:

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

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

关于java - org.ksoap2.serialization.SoapObject 无法转换为 org.ksoap2.serialization.SoapPrimitive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23220502/

相关文章:

c# - Xml序列化-集合属性

algorithm - 哪些应用程序/游戏状态 "delta compression"技术/算法确实存在?

Java对象序列化嵌套对象

java - 未找到 JPA 父 key

java - 没有可检查的 float 操作按钮

java - 如何使用 java 检查数据库连接是关闭还是打开?

android - Rx Observable 定期发射值

android - 如果收到的 TTS 太长,onUtteranceCompleted() 会丢失

java - Twitter4j,未知主机异常

android - 如何删除Android SQLite数据库?