Issue
I'm trying to generate a C-header with "javah - jni " and the javah.exe returns an error I've never seen before. I'm using JNI because I'm using the NDK for C/C++ android development.
Here's the error message:
An exception has occured in the compiler (1.7.0_01).
java.lang.ClassCastException:
com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast to
com.sun.tools.javac.file.JavacFileManager
at com.sun.tools.javac.main.Main.compile(Main.java:411)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:513)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
at com.sun.tools.javah.Main.main(Main.java:46)
Here's the Java file that I use with jni:
package AndroidTest.AccelerometerTest
public class NativeCaller{
final private static String LIB_NAME = "AccelerometerTest";
static
{
System.LoadLibrary( LIB_NAME );
}
public static native int TestMethod();
public static native float ComputePointPosition();
}
I've searched in the Bug Parade of sun but couldn't find anything useful.
EDIT :
This is my platform:
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)
I'm invoking javah like this : javah -jni NativeCaller.java
I call it being in the .java folder.
I've tried to call it with full package name but it can't find the class.
Solution
How are you invoking javah? Make sure you call it with the fully-qualified class name including package name. For example, I just did the following, which worked perfectly fine (I'm on a mac working in the terminal). Also, what is your working platform/java implementation/version?
$ mkdir jnitest
$ cd jnitest
$ mkdir AndroidTest
$ mkdir AndroidTest/AccelerometerTest
$ vim AndroidTest/AccelerometerTest/NativeCaller.java
[pasted your code into the file, fixing two typos]
[missing ';' and loadLibrary starting with lower-case 'l']
[saved the file and exited editor]
$ javac AndroidTest/AccelerometerTest/NativeCaller.java
$ javah -jni AndroidTest.AccelerometerTest.NativeCaller
$ ls
AndroidTest AndroidTest_AccelerometerTest_NativeCaller.h
My java version is:
$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode)
Answered By - Aleks G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.