ClassCastException when trying to apply the same types

I am working on a small Android application that is responsible for loading external code as a plugin form. The app works as a runtime for the compiled classes (tasks) placed on the SD card and provides an overview for those tasks / tests.

Let's say I have a Service class and a Test class (stored in the SD card). When my application starts, the Service and Test classes are loaded into my application. Through a common interface, the Test class has access to all available services .

One of these Test requires multiple services . When I launch my application and run this Test , I get the following error:

System.err﹕ java.lang.ClassCastException: com.test.testcomponent.MathService cannot be cast to com.test.testcomponent.MathService
System.err﹕ at com.test.testcomponent.ServiceTest.onStart(ServiceTest.java:15)
System.err﹕ at com.test.doc.domain.routine.TestExecutor.execute(TestExecutor.java:27)
System.err﹕ at com.test.doc.domain.suite.AsyncTestRunner$6.run(AsyncTestRunner.java:122)
System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)`

      

The first thing that seemed to me was that my application was using another ClassLoader . I checked this, but the application only uses one ClassLoader .

It also doesn't seem to be related to the device / phone the application is running on.

To load external dex classes I use: org.smali: dexlib2: 2.0.3

Solved:

In the end, I used several ClassLoaders that were causing the mentioned problem.

+3


source to share





All Articles