Kyborg2011
Kyborg2011

Reputation: 606

C and Java through Jni

I'm trying to call the java code from S. This method call:


cls = (* env) -> FindClass (env, "org / libsdl / app / SDLActivity");
mid = (* env) -> GetStaticMethodID (env, cls, "play",
"([Ljava / lang / String;) V");
(* env) -> CallVoidMethod (env, cls, mid);

java method:


public static void play () {
track.write (bytes, 0, bytes.length);
}

Cause this error:

03-25 18:17:32.313: WARN / dalvikvm (655): JNI WARNING: JNI method called with exception raised 03-25 18:17:32.313: WARN / dalvikvm (655): in Lorg / libsdl / app / SDLActivity;. main (ILjava / lang / String; [I (GetByteArrayElements) 03-25 18:17:32.313: WARN / dalvikvm (655): Pending exception is: 03-25 18:17:32.323: INFO / dalvikvm (655): Ljava / lang / NoSuchMethodError;: play

finds the class, but can not find a method What's the problem? How to decide?

Upvotes: 0

Views: 2470

Answers (2)

Stephen C
Stephen C

Reputation: 718658

The problem is that the method signature string is incorrect. For a method with no arguments returning void, the method signature string is "()V".

Another point is that a valid type or method signature string will never have spaces in it. Thus a method that takes a String argument and returns void would be

    "([Ljava/lang/String;)V"

rather than

    "([Ljava / lang / String;) V"

Upvotes: 6

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285415

It looks like you're trying to find a method that takes a String parameter when the method in fact takes no parameter.

Upvotes: 2

Related Questions