Exception in thread "main"

Fermé
chimouch - Modifié par chimouch le 22/03/2011 à 10:39
 Profil bloqué - 25 mars 2011 à 02:54
Bonjour,

SVP je suis débutante en java et je veux me connecter à openerp pour pouvoir accéder à la base de donnée, j'ai utilisé ce code:
package test; 

import java.net.MalformedURLException; 
import java.util.ArrayList; 
import java.net.URL; 
import java.util.HashMap; 
import java.util.Vector; 
import org.apache.xmlrpc.XmlRpcException; 
import org.apache.xmlrpc.XmlRpcException; 
import org.apache.xmlrpc.client.XmlRpcClient; 
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; 

public class OpenERP { 
 // connection 
 private XmlRpcClient xmlrpc; 
 // userid, derived from first login 
 private int openERPuserid; 
 // internally stored 
 private String openERPHost; 

 private int openERPPort; 

 private static int default_openERPPort = 8069; 

 private String openERPDB; 

 private String openERPUser; 

 private String openERPPassword; // esp. the password is needed for every request 

public void OpenERP(String host, int port) { 

  openERPHost = host; 

  openERPPort = port; 
        } 
public OpenERP(String host) { 

  openERPHost = host; 

  openERPPort = default_openERPPort; 

} 

public OpenERP(String host, int port, String db, String user, String pass) throws MalformedURLException, XmlRpcException { 

  openERPHost = host; 

  openERPPort = port; 

  openERPDB = db; 

  openERPUser = user; 

  openERPPassword = pass; 


  loginOpenERP(); 

  initializeXMLRPC(); 

 } 
public OpenERP(String host, String db, String user, String pass) throws MalformedURLException, XmlRpcException { 

  openERPHost = host; 

  openERPPort = default_openERPPort; 

  openERPDB = db; 

  openERPUser = user; 

  openERPPassword = pass; 


  loginOpenERP(); 

  initializeXMLRPC(); 

 } 
public String[] list() throws MalformedURLException, XmlRpcException { 

  XmlRpcClient xmlrpcLogin = new XmlRpcClient(); 


  XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl(); 

  xmlrpcConfigLogin.setEnabledForExtensions(true); 


  URL serverURL = null; 

  // processing is done with /db, unlike login (/common) or queries (/object) 
  serverURL = new URL("http", "localhost", 8069, "/xmlrpc/demo"); 

  xmlrpcConfigLogin.setServerURL(serverURL); 


  xmlrpcLogin.setConfig(xmlrpcConfigLogin); 


  // Connect 

  Object[] params = new Object[] {}; 

  Object id = xmlrpcLogin.execute("list", params); 

  Object[] ids = (Object[]) id; 


  String[] strs = new String[ids.length]; 

  for (int i = 0; i < ids.length; i++) { 

   Object idsi = ids[i]; 

   strs[i] = (String)idsi; 

  } 

  return strs; 

 } 
public boolean loginOpenERP(String username, String password) throws MalformedURLException, XmlRpcException { 

  openERPUser = username; 

  openERPPassword = password; 

  return loginOpenERP(); 

 } 
public boolean loginOpenERP() throws MalformedURLException, XmlRpcException a{ 

  XmlRpcClient xmlrpcLogin = new XmlRpcClient(); 

  XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl(); 

  xmlrpcConfigLogin.setEnabledForExtensions(true); 


  URL serverURL = null; 

  // processing is done with /common, unlike queries (/object) 

  serverURL = new URL("http", "localhost", 8069, "/xmlrpc/common"); 

  xmlrpcConfigLogin.setServerURL(serverURL); 


  xmlrpcLogin.setConfig(xmlrpcConfigLogin); 

  // Connect 

  Object[] params = new Object[] { "demo", "admin", "azerty" }; 

  Object id = xmlrpcLogin.execute("login", params); 

  if (id instanceof Integer) 

   openERPuserid = ((Integer) id).intValue(); 


  // return "true" if user id exists 

  return (openERPuserid > 0); 

 } 
private void initializeXMLRPC() throws MalformedURLException { 

  xmlrpc = new XmlRpcClient(); 


  XmlRpcClientConfigImpl xmlrpcConfig = new XmlRpcClientConfigImpl(); 

  xmlrpcConfig.setEnabledForExtensions(true); 


  URL serverURL = null; 

  serverURL = new URL("http", "localhost", 8069, "/xmlrpc/object"); 

  xmlrpcConfig.setServerURL(serverURL); 


  xmlrpc.setConfig(xmlrpcConfig); 

 } 

 public boolean isConnected() { 

  // return "true" if user id exists 

  return (openERPuserid > 0); 

 } 

 public boolean hasModule(String modulename, boolean isInstalled) { 

  OpenERPDomain domain = new OpenERPDomain(); 

  domain.add("name","=",modulename); 

  if (isInstalled) { 

   domain.add("state","=","installed"); 

  } 

  // use a simple search on the module model/table 

  Object[] is = search("ir.module.module", domain); 

  return ((is != null) && (is.length > 0)); 

 } 


 public boolean hasModule(String modulename) { 

  return hasModule(modulename, true); 

 } 

 private Vector<Object> createParams(String model, String action) { 

  Vector<Object> params = new Vector<Object>(); 

  params.add(openERPDB); 

  params.add(openERPuserid); 

  params.add(openERPPassword); 

  params.add(model); 
  params.add(action); 

  return params; 

 } 

 public Object[] search(String model, OpenERPDomain domain) { 

  return search(model, domain.get()); 

 } 


 public Object[] search(String model, Object[] domain) { 

  Vector<Object> params = createParams(model, "search"); 

  params.add(domain); 


  params.add(0); // offset 

  params.add(new Double(2 ^ 63 - (2 ^ 9 + 1)));  


  params.add(0);         


  Object[] resultArray = null; 

  try { 

   Object result = xmlrpc.execute("execute", params); 

   resultArray = (Object[]) result; 

  } catch (XmlRpcException e) { 

   // TODO Auto-generated catch block 

   e.printStackTrace(); 

  } 

  return resultArray; 

 } 


 public Object[] read(String model, Object[] readlist, String[] fieldlist) { 

  Vector<Object> params = createParams(model, "read"); 

  params.add(readlist); 

  params.add(fieldlist); 


  Object[] resultArray = null; 

  try { 

   Object result = xmlrpc.execute("execute", params); 

   resultArray = (Object[]) result; 

  } catch (XmlRpcException e) { 

   // TODO Auto-generated catch block 

   e.printStackTrace(); 

  } 

  return resultArray; 

 } 

 public OpenERPRecordSet readRecords(String model, Object[] readlist, String[] fieldlist) { 

  return new OpenERPRecordSet(this.read(model, readlist, fieldlist)); 

 } 

 public Integer create(String model, HashMap<String, Object> data) { 

  Vector<Object> params = createParams(model, "create"); 

  params.add(data); 


  Integer resultID = null; 

  try { 

   Object result = xmlrpc.execute("execute", params); 

   resultID = (Integer) result; 

  } catch (XmlRpcException e) { 

   // TODO Auto-generated catch block 

   e.printStackTrace(); 

  } 


  return resultID; 


 } 

 public Boolean write(String model, Integer id, HashMap<String, Object> values) { 

  return write(model, new Integer[] { id }, values); 

 } 


 public Boolean write(String model, Integer[] ids, HashMap<String, Object> values) { 

  Vector<Object> params = createParams(model, "write"); 

  params.add(ids); 

  params.add(values); 


  Boolean resultID = null; 

  try { 

   Object result = xmlrpc.execute("execute", params); 
   resultID = (Boolean) result; 

  } catch (XmlRpcException e) { 

   // TODO Auto-generated catch block 

   e.printStackTrace(); 

  } 


  return resultID; 


 } 


}



et pour le main j'ai essayé d'appeler une methode:
/* 

package test; 

import java.net.MalformedURLException; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import org.apache.xmlrpc.XmlRpcException; 


public class test1 { 

     
    public static void main(String[] args) { 

     try{ 

            OpenERP open =new OpenERP("localhost", 8069, "demo", "admin","azerty"); 
             
            //OpenERP open =new OpenERP("localhost"); 
            boolean resultat =false; 
            resultat=  open.loginOpenERP("admin", "azerty"); 
          // resultat=open.loginOpenERP("admin", "azerty"); 
            System.out.println(resultat); 
      } 
        catch (MalformedURLException ex) { 
            Logger.getLogger(test1.class.getName()).log(Level.SEVERE, null, ex); 
        } 

        catch(XmlRpcException e1){ 
              System.out.println("e1"); 


        } 
         
    } 

} 


mais ca marche pas parcequ'il m'affiche l'erreur suivante:
run: 
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class 
        at java.lang.ClassLoader.defineClass1(Native Method) 
        at java.lang.ClassLoader.defineClass(ClassLoader.java:796) 
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144) 
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:382) 
        at java.net.URLClassLoader.access$100(URLClassLoader.java:75) 
        at java.net.URLClassLoader$1.run(URLClassLoader.java:294) 
        at java.net.URLClassLoader$1.run(URLClassLoader.java:288) 
        at java.security.AccessController.doPrivileged(Native Method) 
        at java.net.URLClassLoader.findClass(URLClassLoader.java:287) 
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327) 
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
        at test.OpenERP.loginOpenERP(OpenERP.java:135) 
        at test.OpenERP.<init>(OpenERP.java:58) 
        at test.test1.main(test1.java:21) 
Java Result: 1 
BUILD SUCCESSFUL (total time: 2 seconds) 



Svp si vous pouvez m'aider à résoudre ce probleme

1 réponse

Profil bloqué
25 mars 2011 à 02:54
Vous importez le package peut être un problème
0