JNI: NoSuchMethodError

Status
Nicht offen für weitere Antworten.

Gayson

Bekanntes Mitglied
Hallo!

Ich versuche gerade, mit JNI ein wenig rumzuspielen, ich schaff es einfach nicht, aus C heraus aus einer Java-Datenstruktur was aufzurufen.
Er soll mir lediglich die 0 ausgeben, doch leider bricht er bei GetMethodID ab und wirft auf der Konsole die entsprechende Fehlermeldung und die Java-Exception aus...
D.h. die Klasse Point findet er schon mal...
Wo könnte der Fehler liegen? In der Übergabe der Methodensignatur?
Danke!

Point.java
Code:
public class Point{
	private int x;
	private int y;
	public Point(int x, int y){
		this.x=x;
		this.y=y;
	}
	public int getX(){return x;}
	public int getY(){return y;}
}

PointSum.java
Code:
public class PointSum {
	static {
		System.loadLibrary("PointSum");
	}
	public static native void pointsum( Point p );
	public static void main (String[] argv){
		pointsum(new Point(0,1));
	}
}

PointSum.c
Code:
#include <jni.h>
#include "PointSum.h"
#include <stdio.h>

JNIEXPORT void JNICALL Java_PointSum_pointsum(JNIEnv *env, jclass clazz, jobject o ){
	jmethodID jmid;
	jclass jcls;
	jint result;
	jcls = (*env)->FindClass(env, "Point");
	if (jcls == NULL){
		printf("Error FindClass\n");
		return NULL;
	}
	jmid = (*env)->GetMethodID(env, jcls, "getX","(V)I");
	if (jmid == NULL){
		printf("Error FindMethodID\n");
		return NULL;
	}
  	result = (*env)->CallIntMethod(env, o, jmid);
    printf("\d",result);
}
 

Gayson

Bekanntes Mitglied
Hab den Fehler gefunden, die zu übergebene Signatur war falsch:
Code:
#include <jni.h>
#include "PointSum.h"
#include <stdio.h>

JNIEXPORT void JNICALL Java_PointSum_pointsum(JNIEnv *env, jclass clazz, jobject o ){
	jmethodID jmid;
	jclass jcls;
	jint result;
	jcls = (*env)->FindClass(env, "Point");
	if (jcls == NULL){
		printf("Error FindClass\n");
		return NULL;
	}
	jmid = (*env)->GetMethodID(env, jcls, "getX","()I");
	if (jmid == NULL){
		printf("Error GetMethodID\n");
		return NULL;
	}
  	result = (*env)->CallIntMethod(env, o, jmid);
    printf("%d",result);
}
 

thE_29

Top Contributor
Mh, hast du packages und normalerweise wird eine .h Datei von javah erstellt, hast du die auch, bzw. passen die Methdoenköpfe??
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben