Your code works fine, for me, if I just add the CONTEXT_INCLUDE_CODE flag in the call to createPackageContext.
Why does ClassLoader.loadClass ALWAYS throw ClassNotFoundException in android?
-
11-06-2023 - |
سؤال
Take a look at:
Context contxt = createPackageContext("com.exam.provider", CONTEXT_IGNORE_SECURITY); // I know, the package must be (and IS) already installed ;-)
ClassLoader loader = contxt.getClassLoader();
loader.loadClass("com.exam.provider.MyGestureOverlayView"); // I'm sure this class DOES exist in "com.exam.provider"
But this code always throws java.lang.ClassNotFoundException
. Also note that both android applications share the same user id via:
<manifest
...
android:sharedUserId="whatever"
...
>
I am completely frustrated. Any idea?
المحلول
نصائح أخرى
Is the error at compile-time or run-time
'ClassNotFoundException' here may be because the package is not found at runtime. {after successful compilation}
Uninstalling the app from the device or emulator first solved this problem for me.
لا تنتمي إلى StackOverflow