GetStaticMethodID Problem

Want to load a jfloat array into a java.nio.FloatBuffer in C

The easiest way to do this is using the static method

FloatBuffer.wrap(float[]);

So I get the classID:

jclass floatBufClass = (*env)->FindClass(env,"java/nio/FloatBuffer");

if(floatBufClass == NULL){

return (NULL);

}

This appears to work

then go for the methodID:

jmethodID cid = (*env)->GetStaticMethodID(env, floatBufClass,"wrap","([F)Ljava/nio/FloatBuffer");

if(cid == NULL){

return(NULL);

}

Get the error on the Java side:

Exception in thread"main" java.lang.NoSuchMethodError: wrap

Any ideas?

Jim

[1054 byte] By [jjones3566a] at [2007-11-26 22:48:17]
# 1

<snip>

> > jmethodID cid = (*env)->GetStaticMethodID(env,

> floatBufClass, "wrap", "([F)Ljava/nio/FloatBuffer");

> if(cid == NULL) {

>return(NULL);

>

The 'javap' tool is your friend:

[jim@daisy ~]$ /usr/java/jdk1.6.0/bin/javap -s java.nio.FloatBuffer

Compiled from "FloatBuffer.java"

public abstract class java.nio.FloatBuffer extends java.nio.Buffer implements java.lang.Comparable{

final float[] hb;

Signature: [F

final int offset;

Signature: I

boolean isReadOnly;

Signature: Z

...

...

...

public static java.nio.FloatBuffer wrap(float[]);

Signature: ([F)Ljava/nio/FloatBuffer;

The signature String in calls such as GetStaticMethodID must match the output from 'javap' *exactly*. When referring to non-primitive types in signature Strings the proper form is:

Lsomepacakge/somesubpackage/SomeClass;

You forgot the trailing semi-colon in your code.

Jim S.

Niceguy1a at 2007-7-10 12:07:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Thanks, now that I look at the javap output, I notice that not all signatures have a semi-colon at the end. I can only guess how long it would have taken to figure that out. Thanks again.Jim
jjones3566a at 2007-7-10 12:07:53 > top of Java-index,Java HotSpot Virtual Machine,Specifications...