错误:java.util.Vector无法转换为org.ksoap2.serialization.SoapObject

时间:2018-12-11 16:07:23

标签: java

我需要帮助。

我需要显示用户列表。

我的web服务呼叫是:

/**
     * llistar usuaris
     * @return 
     * - una llista amb tots els usuaris
     *  Si no hi ha usuaris la llista estara blanca.
     * - en altres casos retorna WebServiceCalls.ERROR_CRIDA
     */
        public SoapObject consultarUsuaris(String tipusUsuari, String authId){
            final String metode = "consultarUsuaris";
            SoapObject respostaSoap = null;

            try{         
                //Preparem els arguments del mètode compovarLogin
                Map<String,String> args = new HashMap<>();
                args.put("tipusUsuari",tipusUsuari);
                args.put("authId",authId);
                //Fem la crida al mètode per obtenir-ne la resposta
                 respostaSoap = usarWebService(metode,args);
                //Retornem el valor de "authId"           
            //    return respostaSoap.getPrimitiveProperty("authId").toString(); 
               // System.out.println(respostaSoap.getPrimitiveProperty("authId").toString());
               respostaSoap.getPrimitiveProperty("nom").toString();                 

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

            return respostaSoap;
        }    

我的代码是:(这是我提取信息的地方。)

public Object mostrarUsuaris() {

//Fem trucada a l'altre clase per recuperar el valor de authID
    GamificacIOC ioc = new GamificacIOC();
//AuthId
    Object authId = ioc.authId;
    Object nom = null;

//Truquem la clase on tenim el metode de alta usuari
    WebServiceCalls calls = new WebServiceCalls();

      SoapObject resposta = calls.consultarUsuaris(WebServiceCalls.TIPUS_USUARI_ALUMNE, authId.toString());
      if (resposta == null)
      {                           
          JOptionPane.showMessageDialog(null, "Error falten dades");
      }

      else
      {

          //Si els buttons son plens verifica que sigui correcte
        authId= resposta.getPrimitiveProperty("authId");
      //    nom = resposta.getPrimitiveProperty("nom");
        //authId ens dona el resultat que volem pasar per saber el tipus User


       System.out.println(authId + " nom " +nom);

         //Enviem l'authId per poder saber que usuari es...         
       String resposta2 = calls.tipusUsuari(authId.toString()); 
       System.out.println(authId);

    }

    return authId;

}    }  

我需要提取所有用户的姓名。

mi SOAP UI请求为:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">    <S:Body>
      <ns2:consultarUsuarisResponse xmlns:ns2="http://webservices.gamificacioc.com/">
         <llistarUsuaris>
            <cognom>Maqueda Domenech</cognom>
            <email>xet@jj.com</email>
            <nom>Montse</nom>
            <usuari>mmaquedadomenech</usuari>
         </llistarUsuaris>
         <llistarUsuaris>
            <cognom>Barcia B</cognom>
            <email>jjj@gmail.com</email>
            <nom>Fran</nom>
            <usuari>fbarciab</usuari>
         </llistarUsuaris>
         <llistarUsuaris>
            <cognom>Ignles S</cognom>
            <email>jjj@kkkk.com</email>
            <nom>Xavi</nom>
            <usuari>xignless</usuari>
         </llistarUsuaris>
      </ns2:consultarUsuarisResponse>    </S:Body> </S:Envelope>

请帮助我T_T 它给了我错误,但没有显示任何内容.....

我对webService的了解很少。我有打通的电话。但这不是。

谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!


添加其他信息:

   private SoapObject usarWebService(String metode, Map<String,String> args) 
            throws IOException, HttpResponseException, XmlPullParserException{
        SoapObject peticio = crearPeticio(metode,args);
        SoapSerializationEnvelope embolcall = obtenirEmbolcallPeticio(peticio);
        return cridaWebService(metode,embolcall);
    }




private SoapObject cridaWebService(String metode, SoapSerializationEnvelope envelope) 
            throws IOException, HttpResponseException, XmlPullParserException{
        //Creem l'objecte per fer la crida al web service
        HttpTransportSE httpTransportSE = new HttpTransportSE(GIOC_WEB_SERVICES);
        //Fem la crida
        httpTransportSE.call(metode, envelope);
        return (SoapObject) envelope.getResponse();
    }

这是错误:

java.lang.ClassCastException: java.util.Vector cannot be cast to org.ksoap2.serialization.SoapObject
    at com.gamificacioc.utils.WebServiceCalls.cridaWebService(WebServiceCalls.java:183)
    at com.gamificacioc.utils.WebServiceCalls.usarWebService(WebServiceCalls.java:130)
    at com.gamificacioc.utils.WebServiceCalls.consultarUsuaris(WebServiceCalls.java:299)
    at Alumnes.pantalla_LlistarAlumne.mostrarUsuaris(pantalla_LlistarAlumne.java:130)
    at Alumnes.pantalla_LlistarAlumne.<init>(pantalla_LlistarAlumne.java:82)
    at appEscriptori.pantalla_ProfessorGestioAlumne$3.actionPerformed(pantalla_ProfessorGestioAlumne.java:97)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)






private SoapObject cridaWebService(String metode, SoapSerializationEnvelope envelope) 
            throws IOException, HttpResponseException, XmlPullParserException{
        //Creem l'objecte per fer la crida al web service
        HttpTransportSE httpTransportSE = new HttpTransportSE(GIOC_WEB_SERVICES);
        //Fem la crida
        httpTransportSE.call(metode, envelope);
        return (SoapObject) envelope.getResponse();
    }

0 个答案:

没有答案