1. Download our Official Android App: Forums for Android!

1.5 pre-release - DexClassLoader issue

Discussion in 'Android Apps & Games' started by eborix13, Apr 16, 2009.

  1. eborix13

    eborix13 Lurker
    Thread Starter
    Apr 9, 2009

    Apr 9, 2009

    Seeing that the new 1.5 pre-release has support for loading classes dynamically I immediately tried to see if it works. I used the DexClassLoader(String dexPath, String dexOutputDir, String libPath, ClassLoader parent) constructor. But I soon found out that it works only partially.

    What I am trying to do is dynamically load a class from a given jar file which contains a classes.dex file. If I try to use the current class loader (this.getClass().getClassLoader()) as the "parent" parameter I get a "java.lang.IllegalAccessError: cross-loader access from pre-verified class" error. But if I use the SystemClassLoader as the "parent" parameter everything works out nicely. But using the SystemClassLoader is a problem for me because the class that is loaded using the SystemClassLoader is a subclass of a class which was previously loaded by the current class loader. Casting the derived class to the base class generates a ClassCastException because the base class was not loaded with the same class loader as the derived class.

    Is there a way to solve this problem? Am I doing something wrong? Is there a way to dynamically load a class using the current class loader instead of the system class loader? Is this problem caused by the fact that the 1.5 release is incomplete yet, so perhaps this problem is going to be solved in the final release?

    Thank you...


Share This Page