GetStaticFieldID what's wrong?

764 views
Skip to first unread message

simons....@gmail.com

unread,
Apr 1, 2011, 2:39:13 PM4/1/11
to andro...@googlegroups.com
I'm trying to retrieve the GET_META_DATA static field of the android.content.pm.PackageManager class.
but the call GetStaticFieldID return NULL.

any idea

/* retrieve PackageManager */
jmethodID getPackageManager = (*JEnv)->GetMethodID(JEnv, activityClass, "getPackageManager", "()Landroid/content/pm/PackageManager;");
ASSERT(getPackageManager != NULL);
jobject packageManager = (*JEnv)->CallObjectMethod(JEnv, android_app->activity->clazz, getPackageManager);
ASSERT(packageManager != orxNULL);
jclass packageManagerClass = (*JEnv)->GetObjectClass(JEnv, packageManager);
ASSERT(packageManagerClass != NULL);
/* retrieve GET_META_DATA static field */
jfieldID GET_META_DATA_ID = (*JEnv)->GetStaticFieldID(JEnv, packageManagerClass, "GET_META_DATA", "I");
ASSERT(GET_META_DATA_ID != NULL);  <------------------- ASSERT fails here
jint GET_META_DATA = (*JEnv)->GetStaticIntField(JEnv, packageManagerClass, GET_META_DATA_ID);

TIA

Philippe

simons....@gmail.com

unread,
Apr 4, 2011, 7:03:01 AM4/4/11
to andro...@googlegroups.com
any idea would be welcome...

fadden

unread,
Apr 4, 2011, 2:12:11 PM4/4/11
to android-ndk
On Apr 1, 11:39 am, "simons.phili...@gmail.com"
<simons.phili...@gmail.com> wrote:
> I'm trying to retrieve the GET_META_DATA static field of the
> android.content.pm.PackageManager class.
> but the call GetStaticFieldID return NULL.

PackageManager is an abstract class, which means GET_META_DATA is
defined in a superclass of the class you retrieved. It appears that
Dalvik has a bug where it doesn't search into the superclass for a
static field.

You can work around this by using FindClass to get android/content/pm/
PackageManager and then issuing GetStaticFieldID on that.

simons....@gmail.com

unread,
Apr 5, 2011, 5:03:58 AM4/5/11
to andro...@googlegroups.com
Ok will try...

should i fill a bug on this one?

Tanks for help


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


fadden

unread,
Apr 5, 2011, 1:44:18 PM4/5/11
to android-ndk
On Apr 5, 2:03 am, "simons.phili...@gmail.com"
<simons.phili...@gmail.com> wrote:
> Ok will try...
>
> should i fill a bug on this one?

No need (it's a one-word fix, already done).

Philippe Simons

unread,
Apr 6, 2011, 5:19:36 AM4/6/11
to andro...@googlegroups.com, fadden
Ok

thanks for help, it's working now
and this is more how I would do this in Java. (I'm retrieving the static field of the PackageManager class, not from the object the activity returned)

Philippe


--
Reply all
Reply to author
Forward
0 new messages