JNI helloworld

anyone ever done that Helloworld JNI tutorial??? I got the header file created etc when it comes to doing the C++ side i get the following error...
Compiling...
HelloWorldImp.c
J:\Proj from PC\JNI\JNI Example\HelloWorldImp.c(1) : fatal error C1083: Cannot open include file: 'jni.h': No such file or directory
Error executing cl.exe.
any ideas?
(and i know its a C++ problem!! ;) but its in a Java context --- kinda :))

You are missing something from the command line. This probably wont help you but using gcc on linux, the command for compiling the library file goes
gcc -shared -I/usr/lib/j2sdk1.4.1_01/include/ -I/usr/lib/j2sdk1.4.1_01/include/linux/ HelloWorldImp.c -o libhello.so

Similar Messages

  • Run javah -jni HelloWorld gives error...

    hi all i am new to JNI. i wanted to compiled my HelloWorld.java to header file. in which directory shld i run? i am using jdk1.3.
    this is my error:
    D:\jdk1.3.1\bin>javah -jni HelloWorld
    Error: Class HelloWorld could not be found.
    i hav installed JNI1.2 but not using it yet. what are the settings i shld do?
    thanks to everyone.
    seiw77

    Check your CLASSPATH. Your HelloWorld class should come under the directories listed in the CLASSPATH. Also make sure you include the current working directory "." in the CLASSPATH

  • Problem in compiling C file with JNI

    Hello to all,
    I have a simple JNI tutorial
    But after creating the header file using "javah -jni " command when I use that header file in to the C implementation it gives error
    Following code is of HelloWorld.cpp in which the header file in included
    #include <stdio.h>
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
         printf("Hello World!\n");
         return;
    }The error is
    line number 2 - Unable to open include file "HELLOWORLD.H"
    line number 4 - Declaration syntax errorMy java file "HelloWorld.java" is
    class HelloWorld
         private native void print();
         public static void main(String[] args)
              new HelloWorld().print();
         static
              System.loadLibrary("HelloWorld");
    }I also after coping the file into the include directory of the TurboC but same error arise.
    Please suggest me what to do.
    Thanks in advance

    Yes I used "javah -jni HelloWorld" command after complying the program.
    It produced a header file which I have placed in the same directory in which my project is. Then the same error comes, when I place it in include directory of TurboC give same error.

  • JNI: experience in creating DLLs with G++ (mingw32)?

    Hello.
    I'm trying to create a DLL:
    --------------/HelloWorld.cpp/------
    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayMessage(JNIEnv *env, jobject obj)
    printf("Hello world!\n");
    return;
    I previously created 'HelloWorld.java'
    class HelloWorld
    public native void displayMessage();
    static
    System.loadLibrary("HelloWorldImp");
    I created 'HelloWorld.class'.
    I created the header file 'HelloWorld.h':
    c:> javah -jni HelloWorld
    But I do not have any idea to create the DLL.
    I tried with:
    c:> g++ -I"D:\j2sdk\include" -I"D:\j2sdk\include\win32" HelloWorld.cpp -shared -o HelloWorldImp.dll
    But I get this error message when calling from 'Main.java':
    Exception in thread "main" java.lang.UnsatisfiedLinkError: displayMessage
    at HelloWorld.displayMessage(Native Method)
    at Main.main(Main.java:6)
    In order to get this message I created 'Main.java':
    class Main
    public static void main(String[] args)
    HelloWorld hello = new HelloWorld();
    hello.displayMessage();
    Does anybody have any experience in creating DLLs with G++???
    Thank you very much.

    Or is it better GCC?

  • Calling an external C function from a C file in JNI

    Hello,
    I am trying to call an external C function, from a C file which is being called by a Java file. I am getting an unresolved symbol error. I have tried many things like, making the external C function in the format of JNI, etc, etc. It is still not working. I think it has something to do with linking the two C files. If anyone can please answer this, it would greatly help me. here is the code:
    HelloWorld.c:
    #include <jni.h>
    #include <stdio.h>
    #include "MyOldHello.h"
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL
    Java_HelloWorld_print(JNIEnv *env, jobject obj)
         helloPrint();
         return;
    HelloWorld.java:
    class HelloWorld
         private native void print();
         public static void main(String[] args)
              new HelloWorld().print();
         static
              System.loadLibrary("HelloWorld");
              System.loadLibrary("MyOldHello");
    MyOldHello.c:
    #include <jni.h>
    #include <stdio.h>
    #include "MyOldHello.h"
    void helloPrint()
         printf("\nHello World!\n");
    MyOldHello.h:
    void helloPrint();
    Now i use the Visual C++ command prompt to compile this by saying:
    javac HelloWorld.java
    javah -jni HelloWorld
    cl -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll
    and now it gives me the error saying that there is an unresolved external symbol, which is the call to helloPrint in the file HelloWorld.
    If anyone knows how to solve this, or how to call external C functions from a C file that is being called from a Java file using JNI, please respond.
    Thanks
    Nick

    Hi,
    In your post on velocity review, you did not compile MyOldHello.c. You compiled a C file that included the header file for it and called a method defined in the header. The linker is never going to be able to find the code for this if you do not include the object file for this.
    Try this. You will also have to add in any JNI libraries you need to link against but I am sure you could work that out.
    cl /c MyOldHello.c
    cl /c -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD HelloWorld.c
    cl /LD MyOldHello.obj HelloWorld.obj /FeHelloWorld.dll
    [http://msdn.microsoft.com/en-us/library/f35ctcxw(VS.80).aspx]
    Cheers,
    Shane

  • How to use JNI?

    hi all,
    i know that pure java can't disable alt+tab,i must use JNI with C language. i have a pile of codes to disable the alt+tab in C but i do not know how to do it in JNI...can anyone help?thanks in advance...
    these are my codes in C:
    Private Declare Function SystemParametersInfo Lib "user32" _
    Alias "SystemParametersInfoA" (ByVal uAction As Long, _
    ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
    Private Const SPI_SCREENSAVERRUNNING = 97
    Dim ret As Integer
    Dim pOld As Boolean
    Private Sub Form_Load()
    'The line below calls the function and passes
    'the constant and TRUE to fool Windows into thinking
    'the screensaver is running and FALSE to do the opposite...
    ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    'NOTE: THIS MUST BE SET TO FALSE WHEN
    'THE FORM OR APP CLOSES
    'If you do not set it to false, these keys will not work
    'with any app, or with anything in the Windows Environment...
    ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
    End Sub

    There really isn't a lot to using JNI.
    There are examples on Sun's website:
    http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
    There is also a little more simple example at:
    http://www.inonit.com/cygwin/jni/helloWorld/java.html
    Basically, here are the steps:
    1) Create a simple java applet that will call your C/C++ code.
    For practise, I would just use the HelloWorld example from www.inonit.com:
    package example.jni;
    public class HelloWorld {
         private static native void writeHelloWorldToStdout();
         public static void main(String[] args) {
              writeHelloWorldToStdout();
    2) Name the file with the code above HelloWorld.java and compile it:
    javac HelloWorld.java
    3) Use javah to generate the C header file:
    javah example.jni.HelloWorld
    (You may need to cd to the parent directory of 'example', in this case)
    4) The above line should create a example_jni_HelloWorld.h header file.
    Use this header file in your C/C++ DLL. Make sure your C/C++ compile knows where to find jni.h. In my compiler, I added the following paths:
    C:\J2SDK1.4.1\INCLUDE\
    C:\J2SDK1.4.1\INCLUDE\WIN32
    5) The trickiest part about JNI is passing in and returning parameters.
    If you don't have to pass in or return any parameters, then you're almost done. Replace your C/C++ function protocol with the protocol in the header file you generated. Compile your DLL.
    6) Copy the DLL to a path that it will be found by your Java Applet. (If running on Windows, this would be your System32 or System directory.)
    7) I also had to edit my Path environment variable to include the Java Runtime bin directory. On my machine it was: C:\J2SDK1.4.1\jre\bin
    8) Try running your java applet:
    Java example.jni.HelloWorld
    Good Luck!

  • Jni unable to open header file

    Hi,
    I am new to convert java code to .h file and using in c or c++.
    I got this code from net
    which i implement but i not get success.Please guide me where i am wrong.
    code taken from this url:
    http://www.pacifier.com/~mmead/jni/cs510ajp/example_details.html
    //HelloWorld.java
    class HelloWorld {
      public native void displayMessage();
      static
        System.loadLibrary("HelloWorldImp");
    }after using javac compilation
    javah -jni HelloWorld
    file created
    HelloWorld.h
    //HelloWorldImp.cpp
    #include <stdio.h>
    #include "HelloWorld.h"   // this header file was generated by javah
    JNIEXPORT void JNICALL Java_HelloWorld_displayMessage(JNIEnv *env, jobject obj)
      printf("Hello World!\n");
    }but in turbo c error is coming
    unable to open HelloWorld.h file.
    I don't understand what is wrong.
    I have to set any kind of path or what.
    I kept this header file in same folder but its not working.
    If u know how to call this header file please help me.
    Or i have to use any other compiler please suggest me.
    I am using turbo c compiler.
    Thanks and regards,
    Rakesh Kumar.

    If the include is speicfied with quotes (include "file.h") then it is expected to be in the same directory as the C/CPP file. If hte include is specified as <file.h> then the compiler will look for it in a defined path.Rubbish.
    The compiler will look along the paths defined in the -I argument in both cases. If the file is specified on quotes it will also look in the same path as the.c/.cpp file.
    In this case, the file should be in the same location as the CPP file.
    This is very basic stuff.

  • Where is jni.h

    Hi
    I was doing a tutorial by Beth Stearns at: http://java.sun.com/docs/books/tutorial/native1.1/index.html
    I compiled my java file using javah -jni HelloWorld. which works fine. then i wrote the C file with the following code:
    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    printf("Hello world!\n");
    return;
    However when i compile this file i get the error that it cannot find the 'jni.h' and 'HelloWorld.h' files.
    when i looked under the directory i can find the 'HelloWorld.h' file but i cannot find the 'jni.h' file.
    so really i have 2 questions:
    why cannot the compiler find the HelloWorld.h file
    and where is jni.h located.
    regards
    Qasim

    Create the HelloWorld.h :
    1st. Write OK in HelloWorld.java then compiler to class.
    2nd. use "javah - jni HelloWorld"
    All the flow way is listed below:
    1st. write HelloWorld.java
    2nd. compiler HelloWorld.java to create HelloWorld.class
    3rd. command: javah - jni HelloWorld to make HelloWorld.h
    4th. write your C file
    5th. Be sure to include "jni.h","HelloWorld.h"
    6th. use VC++ ( or others.) to make out DLL file.
    the 6th way like this:
    C:\Program Files\Visual Studio\vc\bin\cl.exe -Ic:\jdk\include -I c:\jdk\include\win32 -LD HelloWorld -FeHelloWorld.dll

  • Jni.h no such file or dir ??? What am I doing wrong ??

    Hello I am following the jni tut and I am at the last part and when I go to compile the .c file I get this error no such file or dir <jni.h>.How can I get the jni.h file?

    First let me say thank you GumB for your time.Ok now this is everything I have done
    1)I have made a java file and comepiled it
    2)I used the javah -jni HelloWorld to make a .h file
    3)I have made the .c file which is posted here
    Ok now my header file and my .class file and the .c file are all in the dir /home/dwa/JavaP
    when I cd /home/dwa/JavaP into my dir and try to use this to compile
    gcc -I/usr/java/j2sdk1.4.0_02/include -I/usr/java/j2sdk1.4.0_02/include/linux \ HelloWorldImp.c -o libhello.so
    I get the errors
    HelloWorldImp.c No such file or directory the file is there in /home/dwa/JavaP
    gcc : No input file
    The HelloWorld.c file is there in /home/dwa/JavaP
    and for the sec error No iput file
    I thought this what the input files
    -I/usr/java/j2sdk1.4.0_02/include -I/usr/java/j2sdk1.4.0_02/include/linux
    any clues ? Also like I said I can compile a reg .c program with know prob in the same dir as well, also this is the .c file now
    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    printf("Hello world!\n");
    return;
    Thank for your time
    Sincerely
    Jimmyzz

  • Error while creating .H header file

    I tried the same example in the JNI Programmer�s Guide and Specification.
    My working Folder - D:\velu\java\workspace.
    I wrote and compile the Helloworld.java here and so the class file also resides here.
    But when I execute javah -jni HelloWorld I am getting the error as
    error: cannot access HelloWorld
    file HelloWorld.class not found
    javadoc: error - Class HelloWorld not found.
    Error: No classes were specified on the command line.  Try -help.experts advice me.

    I GOT IT BY ADDING . TO MY CLASSPATH ENV VAR.
    aNYWAY THANKS FRIENDS.

  • How to put native methods in jar file

    Hi.I have an executable jar file(test.jar) that makes use of other jar files and native methods. For example, test.jar uses Jnpout32.dll. . test.jar , the other jar files and the native methods are all in the same directory. When I created test.jar I wrote a manifest file which specifies the class path of the other jar files and the native methods as follows and provided it as an option in the jar cfmev command.
    Class Path: jdbc.jar Jnpout32reg.dll  //content of manifest.txt  file that I provided to the jar command
    //carriage return I then run the command java -jar test.jar to run the file.
    All I am seeing is the following error message
    Exception in thread "AWT EventQueue-o
    "Java.lang.NoClassDefFoundError.
    gnu/io/SerialPortEventListner"
    {code}
    Any ideas? thanks in advance!
    Edited by: Nostalgia on May 22, 2009 8:05 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You seem to be confusing Java's classpath with your os's path. The classpath only applies to Java classes. See if this discussion helps:
    http://www.inonit.com/cygwin/jni/helloWorld/load.html

  • How to call a C program in java PACKAGE

    am trying to call a method implemented in C from java.
    I followed the instructions of sun.java.com tutorial for the simple example of HelloWorld. It works fine.
    BUT, when I try to do the same in a package, I run into a lot of trouble. I did the following :
    1. Created HelloWorld.java in a package GUI/ and compiled it
    package GUI;
    import java.io.*;
    class HelloWorld {
    public native void displayHelloWorld();
    static {
    System.loadLibrary("hello");
    // Call native method through this from other classes
    public void callinghello() {
    callip();
    public static void main(String[] args) {
    new HelloWorld().displayHelloWorld();
    2. javah -jni HelloWorld -- to create HelloWorld.h
    3. wrote HelloWorldImp.c
    4. g++ -Wall -shared -I/usr/lib/j2sdk1.3/include -I/usr/lib/j2sdk1.3/include/linux HelloWorldImp.c -o libhello.so
    -- compiled and created .so file
    5. Set the package directory in Classpath, path and LD_LIBRARY_PATH
    6. When it is run java GUI.HelloWorld
    I get this error
    Exception in thread "main" java.lang.NoClassDefFoundError: OrionGUI/HelloWorld
    Can anyone help me. If you have any links to how to call native methods in package, please let me know. Thanks.

    GOT IT !!!
    I had to change the name of the method in .h file generated by javah command. On doing
    javac -d ../../classes HelloWorld.java
    go to the ../../classes directory (where you have the class file) and do
    javah HelloWorld
    I got a HelloWorld.h file in which I had
    JNIEXPORT void JNICALL Java_HelloWorld_display(JNIEnv *, jobject);
    I added the package name too:
    JNIEXPORT void JNICALL Java_GUI_HelloWorld_display(JNIEnv *, jobject);
    The HelloWorldImp.c file should have the same name (ie with package) and be in the same directory(ie ../../classes)
    compile and build the shared library to get "libhello.so" file
    gcc -c -fPIC -I/usr/lib/j2sdk1.3/include -I/usr/lib/j2sdk1.3/include/linux HelloWorldImp.c
    gives .o file
    gcc -shared -o libhello.so HelloWorldImp.o
    gives .so file
    then run java with the command in my first message. It works.
    Thanks for the reply "thedracle".

  • Problem related to generation of header file

    hi guys,
    I am getting Exception during the generation of the header file,
    using "javah -jni HelloWorld"
    I am refering jni.pdf (java.sun.com/docs/books/jni/download/jni.pdf )
    I have given that error below
    Exception in thread "main" java.io.IOException: can't find class file HelloWorld.class in java.net.URLClassLoader
    {urls=[file:/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/rt.jar],
    parent=gnu.gcj.runtime.SystemClassLoader{urls=[file:./],
    parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}}
    at gnu.classpath.tools.javah.Main.getClass(libgcj-tools.so.8rh)
    at gnu.classpath.tools.javah.Main.run(libgcj-tools.so.8rh)
    at gnu.classpath.tools.javah.Main.main(libgcj-tools.so.8rh)

    ejp wrote:
    GCJ is what you get in Linux (definitely Ubuntu anyway) as the default Java implementation.GCJ isn't a Java implementation at all, as you will discover when you read its documentation attentively. This is because it doesn't pass the Java certification tests. Ergo whatever it may be it isn't Java.
    This is because of the license for Java not being compatible with the Ubuntu distro license.That may be so, or have been so, but it still isn't Java.I guess if you want to label it, it is the GNU Compiler for Java and associated runtimes. As an open source project for when Java licensing was not very compatible with Linux it served a purpose (even if it served it badly).
    The following is from the GCJ web site. I guess they don't really claim to be 100% Java compliant.
    GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code.
    Compiled applications are linked with the GCJ runtime, libgcj, which provides the core class libraries, a garbage collector, and a bytecode interpreter. libgcj can dynamically load and interpret class files, resulting in mixed compiled/interpreted applications. It has been merged with GNU Classpath and supports most of the 1.4 libraries plus some 1.5 additions.The first step for me with Linux was always to install the Sun JDK so never really found out how bad it really was :)
    Cheers,
    Shane

  • UnSatisfiedLinkError

    Hi,
    I am new to JNI.
    I have a java Program HelloWorld.java and stored in C:\TestDll\Today.
    HelloWorld.java
    class HelloWorld
         private native void print();
         public static void main(String[] args)
         new HelloWorld().print();
         static
         System.loadLibrary("HelloWorld");
    After that I compile the HelloWorld.java and HelloWorld.class file has been created.
    After that i used javah to create a header file.
    (ie) c:\TestDll\Today> javah -jni HelloWorld
    Then the header file HelloWorld.h has been Created.
    HelloWorld.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloWorld */
    #ifndef IncludedHelloWorld
    #define IncludedHelloWorld
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: HelloWorld
    * Method: print
    * Signature: ()V
    JNIEXPORT void JNICALL Java_HelloWorld_print
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    I have installed cygwin compiler in c:
    Now i set the path c:\cygwin\bin
    After that i compiled the c program
    The c program is HelloWorld.c
    #include <jni.h>
    #include <stdio.h>
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env,jobject obj)
         printf("Hello World \n");
         return;
    Now i compile this c program using
    C:\TestDll\Today> gcc -mno-cygwin -I"C:\Program Files\Java\jdk1.6.0_01\include" -I"C:\Program Files\Java\jdk1.6.0_01\include\win32" -shared -o HelloWorld.dll HelloWorld.c
    After executing this command a HelloWorld.dll has been created.
    Now i created a run.bat file
    run.bat
    SET JDK16=C:\Program Files\Java\jdk1.6.0_01
    SET PATH=%JDK16%\bin;%JDK16%\jre\bin;%PATH%
    SET CLASSPATH=C:\Program Files\Java\jdk1.6.0_01\lib\tools.jar;%CLASSPATH%
    java HelloWorld
    When i run this bat file
    (ie) C:\TestDll\Today > run.bat
    Its showing a error message
    Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloWorld.print()V
    at HelloWorld.print(Native Method)
    at HelloWorld.main(HelloWorld.java:6)
    Please help me to solve this problem
    Edited by: Padmanabhanp on Oct 22, 2007 2:24 AM

    It means that you have no classpath to your own class "HelloWorld.class".
    You can modify your run.bat on the line 3 to include current directory, if "HelloWorld.class" is still in "c:\TestDll\Today".
    The result is like this : SET CLASSPATH=C:\Program Files\Java\jdk1.6.0_01\lib\tools.jar;%CLASSPATH%;.;
    Hope my suggestion can help you.

  • How to call a C sort function to sort a Java Array.

    My name is David, I'm interning this summer doing some High Performance Computing work. I'm significantly out of my comfort zone here; I am primarily a network/network security geek, not a programming guy. I took one Java based class called problem solving with programming where we wrote like 3 programs in Java and did everything else in pseudocode and using a program called Alice http://www.alice.org/ to do things graphically. Learned basically no actual programming syntax. Also have done some self-taught perl, but only through one book and I didn't finish it, I only got about half way through it. So my expertise in programming are pretty much null.
    That being said, I currently am tasked with having to figure out how to make JNI work... specifically at this time I am tasked with writing an array in Java, and designing a C program that can be called by means of JNI to sort the array. I have chosen to work with the Merge Sort algorithm. My method of coding is not one where I write the entire thing from scratch, I don't particularly have a need to master languages at this point, rather I just need to make them work. I am interested in learning, but time is of the essence for me right now. So thus far what I have done is take sample codes and tweak them to meet my purpose. However, I currently am unable to make things work. So I am asking for help.
    I am going to paste 3 codes here, the first one will be my basic self-written instructions for JNI (Hello World Instructions), the second one will be my Java Array, and the third one will be my MergeSort function. I am not asking for you to DO my work for me by telling me how to manipulate my code, but rather I am asking for you to send me in the direction of resources that will be of some aid to me. Links, books (preferrably e-books so I don't have to go to a library), anything that you can send my direction that may help will be deeply appreciated. Thanks so much!
    JNI Instructions:
    /*The process for calling a C function in Java is as follows:
    1)Write the Java Program name. Eg. HelloWorld.java
    2)Compile it: javac HelloWorld.java
    3)Create a header file: javah -jni HelloWorld
    4)Create a C program eg. HelloWorld.java
    5)Compile the C program creating a shared library eg. libhello.so (My specifc command is cc -m32 -I/usr/java/jdk1.7.0_05/include -I/usr/java/jdk1.7.0_05/include/linux -shared -o libhello.so -fPIC HelloWorld.c
    6) Copy the library to the java.library.path, or LD_LIBRARY_PATH (in my case I have set it to /usr/local/lib.
    7)Run ldconfig (/sbin/ldconfig)
    8)Run the java program: java HelloWorld. */
    //Writing the code:
    //For the HelloWorld program:
    //In java:
    //You need to name a class:
    class HelloWorld {
    //You then need to declare a native method:
    public native void displayHelloWorld();
    //You now need a static initializer:
    static {
    //Load the library:
    System.loadLibrary("hello");
    /*Main function to call the native method (call the C code)*/
    public static void main(String[] args) {
    new HelloWorld().displayHelloWorld();
    //In C:
    #include <jni.h> //JNI header
    #include "HelloWorld.h" //Header created by the javah -jni command parameter
    #include <stdio.h> //Standard input/output header for C.
    //Now we must use a portion of the code provided by the JNI header.
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIENV *env, jobject obj)
    //Naming convention: Java_JavaProgramName_displayCProgramName
        printf("Hello World!\n");
        return;
    }Java Array:
    class JavaArray {
         private native int MergeSort(int[] arr);
         public static void main(String[] args)
             int arr[] = {7, 8, 6, 3, 1, 19, 20, 13, 27, 4};
         static
             System.loadLibrary("MergeSort");
    }Hacked and pieced together crappy C Merge Sort code:
    #include <jni.h>
    #include <stdio.h>
    #include "JavaArray.h"
    JNIEXPORT jint JNICALL
    Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr[],jint low,jint mid,jint high)
       jint i,j,k,l,b[10];
    l=low;
    i=low;
    j=mid+1;
    while((l<=mid)&&(j<=high))
        if(arr[l]<=arr[j])
           b=arr[l];
    l++;
    else
    b[i]=arr[j];
    j++;
    i++;
    if(l>mid)
    for(k=j;k<=high;k++)
    b[i]=arr[k];
    i++;
    else
    for(k=l;k<=mid;k++)
    b[i]=arr[k];
    i++;
    for(k=low;k<=high;k++)
    arr[k]=b[k];
    void partition(jint arr[],jint low,jint high)
    jint mid;
    if(low<high)
    mid=(low+high)/2;
    partition(arr,low,mid);
    partition(arr,mid+1,high);
    sort(arr,low,mid,high);

    You're doing OK so far up to here:
    Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr[],jint low,jint mid,jint high)This is not correct. It is not what was generated by javah. It would have generated this:
    Java_JavaArray_MergeSort(JNIEnv *env, jobject obj, jintArray arr,jint low,jint mid,jint high)A 'jintArray' is already an array, embedded in an object. You don't have an array of them.
    So you need to restore that, and the header file, the way 'javah' generated them, then adjust your code to call GetIntArrayElements() to get the elements out of 'arr' into a local int[] array, sort that, and then call ReleaseIntArrayElements() to put them back.

Maybe you are looking for

  • I dont have TV SHOWS on my itunes store tool bar - any help ?

    I dont have TV SHOWS on my itunes store tool bar - any help ?

  • How to find built-in functions for PL/SQL

    Hi everyone, Please can someone help me, I am running version 8i, and I am trying to find out how I can access all the built-in functions for PL/SQL. I am new in ORACLE environment and I just want to know all the built-in functions and their usage. T

  • Multiline Processing and Agent Assignment

    I have a multiline container element that I am using in a subflow.  I want the subflow to execute for each line in the multiline container. The objects in the multiline element are, in fact, the agent ids.  I am not sure of how to identify a single e

  • Printing Black on Black

    Heyo, I am building a book in InDesign CS3. It is a photobook with a series of photos with black backgrounds being layed out onto a black layout in indesign. So for the sake of this issue, I am placing black photos on black backgrounds in indesign. H

  • Outlook Calendar items added and deleted at same time

    I have several repeating calendar items (like birthdays) in my Outlook calendar.  When I sync, I find that some are added (that I thought were there before) but some show as added and deleted at the same time to my blackberry... any ideas what may be