J
Jeff Gaynor
Hi,
I am writing a small JNI program. Now, at this point almost the only thing
that it does is to accept a java.io.File object then read the abstract
pathname (the whole program is just a couple of lines, included below). I get
that java throws and AbstractMethodError. I can't figure out why this might
be the case -- getAbstractPath is not abstract. Can anyone help here?
Thanks in Advance,
-- Jeff
======
Note: * PSZ is a pointer to a null-terminated string.
* I am not a C programmer, but am trying my hand at this. Advice/tips
appreciated!
* This is a utility and should just grab the name from a file that is
passed and return
it.
PSZ getFileName(JNIEnv *env, jobject jFile){
/* Variable declarations */
char buffer[256];
jclass fileClass = NULL;
jmethodID mid = NULL;
jstring jfName = NULL;
const char *fName = 0;
/* now for some values */
fileClass = (*env)->FindClass(env, "Ljava/io/File;");
printf("got fileClass\n");
mid = (*env)->GetMethodID(env, fileClass,"getAbsolutePath",
"()Ljava/lang/String;");
printf("got method id\n");
/* it dies right after this print statement... */
jfName = (*env)->CallObjectMethod(env,fileClass,mid);
if(jfName == NULL){
printf("jfName is null\n");
return NULL;
}
printf("got jfName\n");
fName = (*env)->GetStringUTFChars(env, jfName, 0);
printf("copied file name:%s\n", fName);
strcpy(buffer, fName);
(*env)->ReleaseStringUTFChars(env, jfName, fName);
printf("file name = %s\n", buffer);
return buffer;
}
I am writing a small JNI program. Now, at this point almost the only thing
that it does is to accept a java.io.File object then read the abstract
pathname (the whole program is just a couple of lines, included below). I get
that java throws and AbstractMethodError. I can't figure out why this might
be the case -- getAbstractPath is not abstract. Can anyone help here?
Thanks in Advance,
-- Jeff
======
Note: * PSZ is a pointer to a null-terminated string.
* I am not a C programmer, but am trying my hand at this. Advice/tips
appreciated!
* This is a utility and should just grab the name from a file that is
passed and return
it.
PSZ getFileName(JNIEnv *env, jobject jFile){
/* Variable declarations */
char buffer[256];
jclass fileClass = NULL;
jmethodID mid = NULL;
jstring jfName = NULL;
const char *fName = 0;
/* now for some values */
fileClass = (*env)->FindClass(env, "Ljava/io/File;");
printf("got fileClass\n");
mid = (*env)->GetMethodID(env, fileClass,"getAbsolutePath",
"()Ljava/lang/String;");
printf("got method id\n");
/* it dies right after this print statement... */
jfName = (*env)->CallObjectMethod(env,fileClass,mid);
if(jfName == NULL){
printf("jfName is null\n");
return NULL;
}
printf("got jfName\n");
fName = (*env)->GetStringUTFChars(env, jfName, 0);
printf("copied file name:%s\n", fName);
strcpy(buffer, fName);
(*env)->ReleaseStringUTFChars(env, jfName, fName);
printf("file name = %s\n", buffer);
return buffer;
}