Why does ClassLoader.loadClass ALWAYS throw ClassNotFoundException in android?

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?

Answers


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.


Need Your Help

svn diff with vim, but with the proper filetype

svn vim file-type

This blog post gives a simple way to use Vim with svn diff. Unfortunately, Vim doesn't understand the left-hand-side filetype so there's no syntax highlighting. What's the simplest/best way of solv...

Send browser headers via PHP

php apache screen-scraping

How can I send a header to a website as if PHP / Apache is a browser? I'm trying to scrape a site, but it looks like they send a 404 error if it's coming from another server...