Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Crash with QAndroidJniObject::callStaticObjectMethod

[SOLVED] Crash with QAndroidJniObject::callStaticObjectMethod

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Firefell
    wrote on 27 Apr 2014, 17:47 last edited by
    #1

    Hi,

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

    My java code is :
    @
    public class contact extends org.qtproject.qt5.android.bindings.QtActivity {
    private static contact m_instance;
    private ArrayList<String> contactNameList = new ArrayList<String>();

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

    ...
    }

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

    }
    @

    my c++ code :
    @
    void ApplicationInfo::queryContacts()
    {
    qDebug("queryContacts");
    QAndroidJniObject contactNameVector = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/RDVU/contact",
    "getContacts",
    "()Ljava/util/ArrayList;");
    // 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();
    qDebug(contactName.toStdString().c_str());
    }
    }
    }
    @

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      s.frings74
      wrote on 28 Apr 2014, 18:05 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Firefell
        wrote on 29 Apr 2014, 07:34 last edited by
        #3

        I have found !

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

        1 Reply Last reply
        0

        1/3

        27 Apr 2014, 17:47

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved