Android ICS : JNI error attempt to use stale local reference 0x1

SteveL picture SteveL · Apr 2, 2012 · Viewed 19.3k times · Source

After upgrading my phone to android 4.03 ics my game dosent open anymore ,it just closes without any error messege on deviCe and with this on eclipse

04-02 16:55:27.672: E/dalvikvm(26884): JNI ERROR (app bug): attempt to use stale local reference 0x1
04-02 16:55:27.672: E/dalvikvm(26884): VM aborting

My game is mainly writen in java but some parts are in c and thats were i think the problem is (not very hard to figure out since its saying JNI ERROR :) )

Of course i dont know where the problem is so i dont give any code

I didnt had this problem on android 2.3

I dont know if it helps but i get this error too sometimes

04-02 16:55:26.061: E/Adreno200-ES11(26884): <qglDrvAPI_glTexImage2D:1913>: GL_STACK_UNDERFLOW

Answer

Ernest Friedman-Hill picture Ernest Friedman-Hill · Apr 2, 2012

The "stale local reference" error means that you're saving a local reference to some Java object between JNI calls; you need to convert that reference to a global reference using the NewGlobalRef method before doing anything that would cause the reference to persist outside the scope of the one JNI call.

Although strictly this was always necessary -- it's in the JNI spec -- it's only since Ice Cream Sandwich that this actually causes problems on the Android platform.