Calling java function from c++ using jni: Failed to find static method id

Makalele

I'm creating cocos2d-x game (v. 3.4) on mac os using android sdk 4.2.2, but I tried other too. I want to make NativeHelper class to call some native android stuff from c++. I used this tutorial as the base: http://www.cocos2d-x.org/wiki/User_Tutorial-Integrate_AdMob It's working, but I want use a java function with parameters. And there comes errors:

02-13 09:33:20.690: W/dalvikvm(28873): Bogus method descriptor: (I;)V 02-13 09:33:20.690: E/JniHelper(28873): Failed to find static method id of showBanner

Here's java implementation:

public static void showBanner(int position) {
        final int _position = position;
        _appActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if(_appActivity != null){
                    if (!_appActivity.adView.isEnabled()){
                        _appActivity.adView.setEnabled(true);
                    }
                    if (_appActivity.adView.getVisibility() == View.INVISIBLE){
                        _appActivity.adView.setVisibility(View.VISIBLE);
                        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                        if(_position == 0){
                            adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                        }
                        else{
                            adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);                           
                        }
                        _appActivity.adView.setLayoutParams(adParams);
                    }
                }
            }
        });
    }

c++ implementation:

void NativeHelper::showBanner(int position){
    cocos2d::JniMethodInfo t;
    if (cocos2d::JniHelper::getStaticMethodInfo(t, AppActivityClassName, "showBanner", "(I;)V")){

        t.env->CallStaticVoidMethod(t.classID, t.methodID, position);

        t.env->DeleteLocalRef(t.classID);

        isBannerShowing = true;
    }
}

If I just remove position parameter from both function (and change (I;)V to ()V ) it's working like a charm. I tried other parameter types like bool and it also doesn't work.

I thought I maybe did something wrong so I found this tutorial: http://stnguyen.com/cocos2d-x/call-java-functions-from-cpp.html

And calling for example sayHello also doesn't work too:

02-13 09:33:16.955: W/dalvikvm(28873): Bogus method descriptor: (Ljava/lang/String;I;)V 02-13 09:33:16.955: E/JniHelper(28873): Failed to find static method id of sayHello

I'm using ndk r9, but tried r10 too. I'm basically out of ideas...

Vladimir Berezkin

You mistyped. It should be "(I)V", not "(I;)V"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a static void Java method from JNI

From Dev

Calling a Java Method from the native code using jni

From Java

Call static Java method from separate thread using JNI

From Dev

JNI: Calling a java method from C periodically is not working

From Dev

Java JNI NullPointerException after calling method from C with valid pointers

From Dev

Calling a static template method from a template function

From

Calling Golang from Java using JNI on Windows leads to "A dynamic link library (DLL) initialization routine failed"

From Dev

Calling a Java static method with generics from Scala

From Java

Calling Java Main method from static block

From Dev

How to call a function with arguments in C++ from JAVA using JNI?

From Dev

Calling a Java static function from Clojure

From Java

calling static method in java

From Dev

Calling non static method from static method USING instance created in the static method

From Dev

Error while calling C# from java using jni4net from 64 bit Os

From Dev

Java calling a print method from a main function and using data from another separate method

From Dev

Sending jbyte array to Java method failed using JNI

From Dev

Calling a javascript function from java method in Cordova

From Java

A java runtime error with a native JNI static method for C++ implementation

From Java

Calling Java method from JavaScript using ScriptEngine

From Dev

JNI : Unable to find java class from native method in a callback

From Dev

How to pass char array from C JNI function to Java method as byte[]

From Dev

Calling RenderScript from C / JNI

From Dev

Efficiency of java static method calling

From Dev

Calling a static Swift Method from within Obj-C

From Dev

Blazor: Invoking C# static method from JS function called from HTML onclick--why can't the JS find the method?

From Dev

Calling a non static method from a in a static context

From Dev

JNI calling Java from C++ with multiple threads

From Dev

C++ calling a static method

From Dev

What's "Method Signature" parameter when calling a Java method using JNI?

Related Related

  1. 1

    Calling a static void Java method from JNI

  2. 2

    Calling a Java Method from the native code using jni

  3. 3

    Call static Java method from separate thread using JNI

  4. 4

    JNI: Calling a java method from C periodically is not working

  5. 5

    Java JNI NullPointerException after calling method from C with valid pointers

  6. 6

    Calling a static template method from a template function

  7. 7

    Calling Golang from Java using JNI on Windows leads to "A dynamic link library (DLL) initialization routine failed"

  8. 8

    Calling a Java static method with generics from Scala

  9. 9

    Calling Java Main method from static block

  10. 10

    How to call a function with arguments in C++ from JAVA using JNI?

  11. 11

    Calling a Java static function from Clojure

  12. 12

    calling static method in java

  13. 13

    Calling non static method from static method USING instance created in the static method

  14. 14

    Error while calling C# from java using jni4net from 64 bit Os

  15. 15

    Java calling a print method from a main function and using data from another separate method

  16. 16

    Sending jbyte array to Java method failed using JNI

  17. 17

    Calling a javascript function from java method in Cordova

  18. 18

    A java runtime error with a native JNI static method for C++ implementation

  19. 19

    Calling Java method from JavaScript using ScriptEngine

  20. 20

    JNI : Unable to find java class from native method in a callback

  21. 21

    How to pass char array from C JNI function to Java method as byte[]

  22. 22

    Calling RenderScript from C / JNI

  23. 23

    Efficiency of java static method calling

  24. 24

    Calling a static Swift Method from within Obj-C

  25. 25

    Blazor: Invoking C# static method from JS function called from HTML onclick--why can't the JS find the method?

  26. 26

    Calling a non static method from a in a static context

  27. 27

    JNI calling Java from C++ with multiple threads

  28. 28

    C++ calling a static method

  29. 29

    What's "Method Signature" parameter when calling a Java method using JNI?

HotTag

Archive