Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. jstring -> type name / unexpected expression
Forum Updated to NodeBB v4.3 + New Features

jstring -> type name / unexpected expression

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 395 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
    Flaming Moe
    wrote on 8 Nov 2023, 20:46 last edited by
    #1

    Hello there,

    am trying to call a static Java method which takes a string as argument.

    QJniObject string1 = QJniObject::fromString(song);
        QJniObject::callStaticMethod<void>(
                        "org/qtproject/example/androidnotifier/MusicPlayer",
                        "play",
                        "(Ljava/lang/String;)I" ,
                        string1.object()<jstring>());
    

    I´m getting the error "unexpected type name 'jstring': expected expression" and can´t figure out, if I´m missing to include a library or something else.

    Has someone an idea?

    A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

    C 1 Reply Last reply 8 Nov 2023, 22:41
    0
    • F Flaming Moe
      8 Nov 2023, 20:46

      Hello there,

      am trying to call a static Java method which takes a string as argument.

      QJniObject string1 = QJniObject::fromString(song);
          QJniObject::callStaticMethod<void>(
                          "org/qtproject/example/androidnotifier/MusicPlayer",
                          "play",
                          "(Ljava/lang/String;)I" ,
                          string1.object()<jstring>());
      

      I´m getting the error "unexpected type name 'jstring': expected expression" and can´t figure out, if I´m missing to include a library or something else.

      Has someone an idea?

      C Offline
      C Offline
      ChrisW67
      wrote on 8 Nov 2023, 22:41 last edited by
      #2

      I think the last line is a little too parentheses-heavy:

      QJniObject string1 = QJniObject::fromString(song);
      QJniObject::callStaticMethod<void>(
                        "org/qtproject/example/androidnotifier/MusicPlayer",
                        "play",
                        "(Ljava/lang/String;)I" ,
                        string1.object<jstring>());
      
      F 1 Reply Last reply 9 Nov 2023, 07:04
      0
      • C ChrisW67
        8 Nov 2023, 22:41

        I think the last line is a little too parentheses-heavy:

        QJniObject string1 = QJniObject::fromString(song);
        QJniObject::callStaticMethod<void>(
                          "org/qtproject/example/androidnotifier/MusicPlayer",
                          "play",
                          "(Ljava/lang/String;)I" ,
                          string1.object<jstring>());
        
        F Offline
        F Offline
        Flaming Moe
        wrote on 9 Nov 2023, 07:04 last edited by Flaming Moe 11 Sept 2023, 07:04
        #3

        @ChrisW67
        There is one thing i´m defenetly doing wrong I see now - the 'I' behind the
        (Ljava/lang/String;)
        is wrong, since I call a void-return method.

        QJniObject string1 = QJniObject::fromString(song);
            QJniObject::callStaticMethod<void>(
                            "org/qtproject/example/androidnotifier/MusicPlayer",
                            "play",
                            "(Ljava/lang/String;)I" ,
                            string1.object()<jstring>());
        

        May be there is a flaw in the example .
        In the c-code part of the following is a comma after the method name "fromNumber"

        // C++ code
        QJniObject stringNumber = QJniObject::callStaticObjectMethod("org/qtproject/qt/TestClass",
                                                                     "fromNumber",
                                                                     "(I)Ljava/lang/String;", 10);
        

        while here isn´t a comma after "stringArray"

        // C++ code
        QJniObject string1 = QJniObject::fromString("String1");
        QJniObject string2 = QJniObject::fromString("String2");
        QJniObject stringArray = QJniObject::callStaticObjectMethod<jstringArray>(
                                                                    "org/qtproject/qt/TestClass",
                                                                    "stringArray"
                                                                    string1.object<jstring>(),
                                                                    string2.object<jstring>());
        

        A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

        C 1 Reply Last reply 9 Nov 2023, 08:42
        0
        • F Flaming Moe
          9 Nov 2023, 07:04

          @ChrisW67
          There is one thing i´m defenetly doing wrong I see now - the 'I' behind the
          (Ljava/lang/String;)
          is wrong, since I call a void-return method.

          QJniObject string1 = QJniObject::fromString(song);
              QJniObject::callStaticMethod<void>(
                              "org/qtproject/example/androidnotifier/MusicPlayer",
                              "play",
                              "(Ljava/lang/String;)I" ,
                              string1.object()<jstring>());
          

          May be there is a flaw in the example .
          In the c-code part of the following is a comma after the method name "fromNumber"

          // C++ code
          QJniObject stringNumber = QJniObject::callStaticObjectMethod("org/qtproject/qt/TestClass",
                                                                       "fromNumber",
                                                                       "(I)Ljava/lang/String;", 10);
          

          while here isn´t a comma after "stringArray"

          // C++ code
          QJniObject string1 = QJniObject::fromString("String1");
          QJniObject string2 = QJniObject::fromString("String2");
          QJniObject stringArray = QJniObject::callStaticObjectMethod<jstringArray>(
                                                                      "org/qtproject/qt/TestClass",
                                                                      "stringArray"
                                                                      string1.object<jstring>(),
                                                                      string2.object<jstring>());
          
          C Offline
          C Offline
          ChrisW67
          wrote on 9 Nov 2023, 08:42 last edited by
          #4

          @Flaming-Moe Yes, that is a missing comma in the documentation. Feel free to raise a bug if you cannot find it already reported.

          F 1 Reply Last reply 10 Nov 2023, 14:04
          0
          • F Flaming Moe has marked this topic as solved on 10 Nov 2023, 14:03
          • C ChrisW67
            9 Nov 2023, 08:42

            @Flaming-Moe Yes, that is a missing comma in the documentation. Feel free to raise a bug if you cannot find it already reported.

            F Offline
            F Offline
            Flaming Moe
            wrote on 10 Nov 2023, 14:04 last edited by
            #5

            @ChrisW67 Even after your former post I haven´t noticed the wrong paranthesis after my ".object" until yesterday evening after staring at goats for a loooong time

            A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

            1 Reply Last reply
            0

            1/5

            8 Nov 2023, 20:46

            • Login

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