Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Crash with QAndroidJniObject::callStaticObjectMethod

    Mobile and Embedded
    2
    3
    2648
    Loading More Posts
    • 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
      Firefell last edited by

      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 Reply Quote 0
      • S
        s.frings74 last edited by

        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 Reply Quote 0
        • F
          Firefell last edited by

          I have found !

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post