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?

Dave G
  • 9,639
  • 36
  • 41
şirket için
  • 103
  • 1
  • 1
  • 8

1 Answers1

1

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

James
  • 8,512
  • 1
  • 26
  • 28
  • And so that's without the file extension (.class). It's very similar to the java command. – Tom Blodget Dec 09 '14 at 11:24
  • Thanks, I solved it. In addition to what you said, I should have used javah command at the parent directory of package directory. – şirket için Dec 09 '14 at 13:49
  • @ş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. – James Dec 09 '14 at 15:55