Results 1 to 16 of 16
Thread: JNI Help
- 09-19-2012, 11:08 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
- 09-20-2012, 01:21 AM #2
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
if no one can figure out why this doesnt work can someone javah this for me and post the header file
Java Code:public class Console { static { System.loadLibrary("console"); } /** * Wipes all text off the console screen */ public native static void clearScreen(); private native static void setColor(char background, char foreground); /** * Sets the color of the console in hex the java program is running on may not work on all consoles * @param background color * @param foreground color */ public static void setColor(byte background, byte foreground) { String background2 = Integer.toHexString(background); String foreground2 = Integer.toHexString(foreground); char f=foreground2.charAt(0); char b=background2.charAt(0); setColor(b,f); } }
-
Re: JNI Help
I just did a manual javah run and got this result:
yr12_m09_b_Console.h
Note though that my Console class uses this package:Java Code:/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class yr12_m09_b_Console */ #ifndef _Included_yr12_m09_b_Console #define _Included_yr12_m09_b_Console #ifdef __cplusplus extern "C" { #endif /* * Class: yr12_m09_b_Console * Method: clearScreen * Signature: ()V */ JNIEXPORT void JNICALL Java_yr12_m09_b_Console_clearScreen (JNIEnv *, jclass); /* * Class: yr12_m09_b_Console * Method: setColor * Signature: (CC)V */ JNIEXPORT void JNICALL Java_yr12_m09_b_Console_setColor (JNIEnv *, jclass, jchar, jchar); #ifdef __cplusplus } #endif #endif
package yr12.m09.b;
and the package name will be part of the java name in the header file above. above.
- 09-20-2012, 02:29 AM #4
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
im confused about what i have to do now that you have put it in a package named yr12_m09_b
- 09-23-2012, 03:43 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
i hate to bother people but can someone javah this for me it still wont work
Java Code:public class Console { private Console() { } static { System.loadLibrary("console"); } /** * Sets the console color back to it's defaults */ public static void restoreColor() { setColor(0,7); } /** * Wipes all text off the console screen */ public native static void clearScreen(); private native static void setColor(char background, char foreground); /** * Sets the color of the console in hex the java program is running on may not work on all consoles * @param background color * @param foreground color */ public static void setColor(int background, int foreground) { String background2 = Integer.toHexString(background); String foreground2 = Integer.toHexString(foreground); char f=foreground2.charAt(0); char b=background2.charAt(0); setColor(b,f); } /** * Halts the console IO until the user presses a key on the console */ public static native void pause(); }
-
Re: JNI Help
You need to be able to use these tools yourself if you're going to progress. Are you calling javah from the command line? If so, what's wrong with this effort? What's not working right? What error messages are you getting?
- 09-23-2012, 05:45 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
watch the video mostly invalid class exceptions idk
-
Re: JNI Help
The video doesn't work for me, poor resolution. If you still need our help, consider describing exactly what's going wrong including showing your error messages. If you are running javah on the command line, you can copy the entire text from the cmd window and paste it here.
- 09-23-2012, 06:42 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
I am running these commands and get this error
javac Console.java
javah -jni Console.class
C:\Users\Joshy\Desktop\console>javac Console.java
C:\Users\Joshy\Desktop\console>javah -jni Console.class
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class
name: Console.class
at com.sun.tools.javac.api.JavacTool.getTask(JavacToo l.java:177)
at com.sun.tools.javac.api.JavacTool.getTask(JavacToo l.java:68)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:5 09)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:3 35)
at com.sun.tools.javah.Main.main(Main.java:46)
- 09-23-2012, 08:45 PM #10
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
Re: JNI Help
Run
javah - h
You will then see the line -
<classes> are specified with their fully qualified names.
"Fully qualified" means you need the package and class name. e.g. your.package.Console
- 09-23-2012, 10:10 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
im using the default package
Last edited by jsobel; 09-23-2012 at 10:14 PM.
-
Re: JNI Help
I wouldn't do Console.class but would simply use Console and would probably add the classpath option, -cp . For example
Note the period before Console and the spaces around the period, all very important. Again note that I'm using the class's name, Console, but without the .class extension.Java Code:javah -cp . Console
Last edited by Fubarable; 09-23-2012 at 10:31 PM.
- 09-23-2012, 11:29 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
It worked thanks so much
-
Re: JNI Help
You're welcome. Glad you've got it working. Note that the -h option as was mentioned above gives you "help" information on how to run javah (as noted above).
- 09-23-2012, 11:50 PM #15
Member
- Join Date
- Apr 2012
- Posts
- 68
- Rep Power
- 0
Re: JNI Help
why do i need to use the -cp option
-
Re: JNI Help


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks