Important: Please read the Qt Code of Conduct -

[SOLVED] Crash with QAndroidJniObject::callStaticObjectMethod

  • Hi,

    I use QAndroidJniObject::callStaticObjectMethod to get a list of contacts which is an ArrayList<String>.

    My java code is :
    public class contact extends {
    private static contact m_instance;
    private ArrayList<String> contactNameList = new ArrayList<String>();

    public contact(){
        m_instance = this;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {


    public void onDestroy()
    public static ArrayList<String> getContacts(){
        Log.d(QtApplication.QtTAG, "Call getContacts");
        return m_instance.contactNameList;


    my c++ code :
    void ApplicationInfo::queryContacts()
    QAndroidJniObject contactNameVector = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/RDVU/contact",
    // Test if result is valid
    if( contactNameVector.isValid() ){
    jint size = contactNameVector.callMethod<jint>("size");
    for (int i = 0; i < size; ++i) {
    // Getting Contact name
    QAndroidJniObject jContactName = contactNameVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
    QString contactName = jContactName.toString();

    I have this error :
    D/Qt (23861): ../RDVU/core/src/applicationinfo.cpp:85 (void RDVU::ApplicationInfo::queryContacts()): queryContacts
    D/Qt (23861): Call getContacts
    E/dalvikvm(23861): JNI ERROR (app bug): accessed stale local reference 0x15 (index 5 in a table of size 0)
    E/dalvikvm(23861): VM aborting

    I don't understand why I have this error. I read the Qt notification code example to search if I have missed something (like androidextras).

    I work with Android 4.4 and Qt 5.2.1.

    Thank you for your help.

  • The method getContacts() return the instance of class "contact". But I do not see any code that creates this instance. Also, the variable m_instance is not initialized, so the function returns a random value.

  • I have found !

    I forget add the contact activity in the AndroidManifest.xml :(

Log in to reply