0

I want to create c library and use it in my java code on an Linux OS. I'm trying to understand and implement natural library concept. I'm following this tutorial http://diglib.stanford.edu:8091/~testbed/doc/JavaUsage/JNI/tutorial.txt

Which is helpful me to understand concept a little. However, I get errors when I try to do it myself. I searced for errors I am getting but none of solutions helped.

Main class code and class for natural library I wrote is as follows:

package natLib;
import natLib.getKeyPressed;
public class main {
public static void main(String[] args) {
    getKeyPressed natlab=new getKeyPressed();
    char c=natlab.keyboardPressedKey();

}
}

package natLib;    
public class getKeyPressed {
static {
 System.loadLibrary("natlab");
    }
public native char keyboardPressedKey();
}

when I write "javac main.java" I get errors like

"main.java:6: error: cannot find symbol getKeyPressed natlab=new getKeyPressed();"

And when I skip for main and just do javac prcess for class with native method, try to obtain a header file javah -jni getKeyPressed.class

Although there is a file as getKeyPressed.class, I get errors like:

"Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name:     getKeyPressed.class"

I try it without .class extention it says

"Error: Could not find class file for 'getKeyPressed'."

It says that even when I make getKeyPressed class file by copying getKeyPressed.class.

It seems I am making a major mistake, any suggestions to solve this?

1 Answer 1

1

javah expects a fully qualified classname. (e.g. natLib.getKeyPressed, not just getKeyPressed)

Sign up to request clarification or add additional context in comments.

3 Comments

And so that's without the file extension (.class). It's very similar to the java command.
Thanks, I solved it. In addition to what you said, I should have used javah command at the parent directory of package directory.
@şirketiçin That's going to be the case with most java tools you'll ever use, since the package structure and directory structure are tightly coupled together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.