문제

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?

도움이 되었습니까?

해결책

Your code works fine, for me, if I just add the CONTEXT_INCLUDE_CODE flag in the call to createPackageContext.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top