How to obtain a new instance of a class which was modified by BCEL?

When I execute this code, a exception "java.lang.NoSuchFieldError" appears.

The goal of  this code is to remove the field "libelle".

Have you an idea ?

thanks.


    ClassGen clazz =new ClassGen(Repository.lookupClass(GenerateurVapeur.class));

    // Get the field "libelle".
    Field prpReelle =  clazz.containsField("libelle");

    // Remove the field.        
    if(prpReelle!=null)
         clazz.removeField(prpReelle);
                
    JavaClass classeJava = clazz.getJavaClass();

    try{

      // Save the class
      dumpClass(classeJava,GenerateurVapeur.class);

      org.apache.bcel.util.ClassLoader cl = new
org.apache.bcel.util.ClassLoader(ClassLoader.getSystemClassLoader());

      Class newClass =  cl.loadClass(GenerateurVapeur.class.getName());
      
       // Try to get a new instance of "GenerateurVapeur"       
      GenerateurVapeur newInstance = (GenerateurVapeur)newClass.newInstance();

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to