Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JNI -- getting AbstractMethodError

Reply
Thread Tools

JNI -- getting AbstractMethodError

 
 
Jeff Gaynor
Guest
Posts: n/a
 
      05-25-2004
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;
}



 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      05-25-2004
On Tue, 25 May 2004 09:16:10 -0500 (CDT), Jeff Gaynor wrote:

> I get that java throws and AbstractMethodError. I can't figure out
> why this might be the case -- getAbstractPath is not abstract.


[...]

> 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;");


The argument to FindClass should be "java/io/File". I believe that
some JVMs also accept the "signature" format you've used here, but not
all do, and this format isn't the one used in the Sun sources.

Note that you could also use GetObjectClass(env,jFile) in this case,
and avoid the issue altogether.

> printf("got fileClass\n");
> mid = (*env)->GetMethodID(env, fileClass,"getAbsolutePath",
> "()Ljava/lang/String;");
> printf("got method id\n");


I suggest that you check for NULL after FindClass() and again after
GetMethodID() before proceeding. Whenever a JNI function fails, you
can call this to see why:

if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
}

> /* it dies right after this print statement... */
> jfName = (*env)->CallObjectMethod(env,fileClass,mid);


Here you are attempting to call an instance method on the class
itself. The second argument should be jFile, not fileClass.

> 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;
> }


/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange runtime error: AbstractMethodError Oliver Wong Java 11 02-09-2007 12:17 AM
java.lang.AbstractMethodError: at the org.apache.xerces.dom.DOMImplementationImpl.createLSOutput() poorichard@gmail.com Java 2 09-18-2006 02:08 AM
JDBC issues with setBinaryStream an AbstractMethodError and a cast gimme_this_gimme_that@yahoo.com Java 1 05-19-2005 08:40 PM
IBM's JNI fails where Sun's JNI works Alex Hunsley Java 4 11-04-2003 10:34 AM
debugging java AbstractMethodError Bin Xin Java 3 08-18-2003 03:23 PM



Advertisments