2

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?

Joseph_Marzbani
  • 1,796
  • 4
  • 22
  • 36

3 Answers3

3

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

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40
  • I can't believe that. My only mistake was to type 'spaces' between CONTEXT_INCLUDE_CODE and CONTEXT_IGNORE_SECURITY; like this: "CONTEXT_IGNORE_SECURITY | CONTEXT_INCLUDE_CODE". It is a habit from C++ times ;-). I changed it to "CONTEXT_IGNORE_SECURITY|CONTEXT_INCLUDE_CODE" and it works like a charm. yahoooooooooooooo – Joseph_Marzbani Mar 09 '14 at 05:04
0

Is the error at compile-time or run-time

'ClassNotFoundException' here may be because the package is not found at runtime. {after successful compilation}

Nik theGeeK
  • 181
  • 12
0

Uninstalling the app from the device or emulator first solved this problem for me.

Ron
  • 91
  • 1
  • 5