Jni with VC++  ACCESS_VIOLATION

i implemented the "cpp" file using jni signature
in my cpp file i am loading a dll and calling fuction from that( of a class in dll)
it producess dll using Cl compiler but when i run java programm it gives me
EXCEPTION_ACCESS_VIOLATION

Most likely reason is because there is a bug in the JNI code.
Do you check return values after every JNI function call?
Do you check for exceptions after every java method call via JNI?

Similar Messages

  • JNI with different versions of jdk

    Hi
    We currently have some JNI code that is running under jdk1.1.8. We are trying to upgrade to jdk1.2.2, and are fidning that the JNI is not working.
    Using jdk 1.2.2 I have re-compiled the Java class with the native methods, re-generated the javah header file, and made sure that the C program includes the right version of jni.h.
    When we try to call a native method that should return a String, it just returns null.
    Can anyone advise me on this - I am at my wits end!
    many thanks
    Lyndsey

    Need a bit more info. I've used JNI with 1.2.2 and it works fine.

  • How to use jni with ervlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    JNI is done in servlets that same way as other java.
    I suspect your problem is in the environment and perhaps how servlets work. It doesn't have anything to do with JNI itself.

  • How to use JNI with Servlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    hi,
    I am also facing the same problem,
    when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
    stack: java.lang.UnsatisfiedLinkError: createSocket
         at RelayConnector.createSocket(Native Method)
         at RelayServlet.doGet(RelayServlet.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
         at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
    It seems i have to do some path settings in my iplenet web server.
    If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,....

  • JNI with applet

    hello
    I want to use JNI with the applet ,could any one give me helloworld applet using JNI
    Thank you

    hello
    I want to use JNI with the applet ,could any one give
    me helloworld applet using JNI
    Thank youhttp://java.sun.com/sfaq/index.html#prevent

  • Can I use JNI with C#?

    Hi,
    I read many tutorials about using JNI with C or C++. Now, I wonder if actually JNI can also be used with C#? I have my machine installed with C# and Java. I really wanna learn about JNI but don't think to install C or C++.
    If it's possible, can someone provide me some examples?
    Regards,

    I think you would need to write a JNI bridge in C++ that would call your C# code. If your C# code is exposed in .Net web services you could use that avenue instead.

  • Application crashes when using JNI with Jdk 1,2, 1.3 and 1.4

    Hi!
    I have this application that has a GUI written in Java and a file parser written in C. JNI is used to connect these parts together. The problem is that the application only works when I am using jdk 1.1.8 but not when using jdk1.2, jdk1.3 or jdk1.4. I am running the application on a Solaris 8 machine.
    I have not written the application myself but I am going to be working with it from now on. But I have today little knowledge with JNI and I have tried different approaches to solve the problem. For example I have tried to used DDD together with GDB to find out what the problem is but with no luck. When I run the application using jdk1.4 I get the following error when the JVM crashes:
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : 10 occurred at PC=0xFA023164
    Function=Java_Bitmap_setDebug+0x1C
    Library=/usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
    Current Java thread:
    at Bitmap.setDebug(Native Method)
    at DisplayPanel.loadFile(DisplayPanel.java:396)
    at MicPlot.loadFile(MicPlot.java:1452)
    at MicPlot.loadFile(MicPlot.java:1441)
    at MicPlot.miOpen_Action(MicPlot.java:1267)
    at MicPlot$SymAction.actionPerformed(MicPlot.java:1184)
    at java.awt.MenuItem.processActionEvent(MenuItem.java:588)
    at java.awt.MenuItem.processEvent(MenuItem.java:548)
    at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
    at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Dynamic libraries:
    0x10000 /opt/java/jdk1.4/bin/java
    0xff360000 /usr/lib/libthread.so.1
    0xff3a0000 /usr/lib/libdl.so.1
    0xff280000 /usr/lib/libc.so.1
    0xff270000 /usr/platform/SUNW,Ultra-4/lib/libc_psr.so.1
    0xfe000000 /opt/java/j2sdk1.4.1/jre/lib/sparc/client/libjvm.so
    0xff220000 /usr/lib/libCrun.so.1
    0xff200000 /usr/lib/libsocket.so.1
    0xff100000 /usr/lib/libnsl.so.1
    0xff1d0000 /usr/lib/libm.so.1
    0xff250000 /usr/lib/libw.so.1
    0xff0e0000 /usr/lib/libmp.so.2
    0xff0b0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/native_threads/libhpi.so
    0xff080000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libverify.so
    0xff030000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libjava.so
    0xfe7e0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libzip.so
    0xfe4e0000 /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.2
    0xedd00000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libawt.so
    0xfc480000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libmlib_image.so
    0xfc410000 /opt/java/j2sdk1.4.1/jre/lib/sparc/motif21/libmawt.so
    0xeda80000 /usr/dt/lib/libXm.so.4
    0xfa090000 /usr/openwin/lib/libXt.so.4
    0xfa3d0000 /usr/openwin/lib/libXext.so.0
    0xfc7e0000 /usr/openwin/lib/libXtst.so.1
    0xed980000 /usr/openwin/lib/libX11.so.4
    0xfa2a0000 /usr/openwin/lib/libdps.so.5
    0xfa3b0000 /usr/openwin/lib/libSM.so.6
    0xfa1d0000 /usr/openwin/lib/libICE.so.6
    0xed880000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libfontmanager.so
    0xfa390000 /usr/openwin/lib/locale/common/xlibi18n.so.2
    0xfa1b0000 /usr/openwin/lib/locale/iso8859-1/xomEuro.so.2
    0xfa190000 /usr/lib//liblayout.so
    0xfa050000 /usr/openwin/lib/locale/common/ximlocal.so.2
    0xfa010000 /usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
    Local Time = Thu Oct 3 13:32:47 2002
    Elapsed Time = 35
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.4.1-beta-b14 mixed mode)
    # An error report file has been saved as hs_err_pid27692.log.
    # Please refer to the file for further information.
    Abort
    From this information I think that the problem should be in the native method setDebug. But I have tried to set a breakpoint at the beginning of that function in the C part but with no luck. The application crashes before it reaches that position in the C file.
    What could possibly go wrong between the setDebug function in the C part and the function call in the Java part?
    When using GDB, GDB cannot figure out what is wrong it just returns a hex address, no function name.
    I would really appreciate some help. I have tried everything that I can come up with!
    Best regards
    Lars

    I have figured out that the application fails on its first call to the native methods.
    So I have this Bitmap class that contains all the native calls and it is defined shortly as follow:
    public class Bitmap {
    static {
    System.loadLibrary("BitmapImpl");
    native void setDebug(int debuglevel, int statistics);
    There are many more native methods defined in Bitmap, but I only show the setDebug method because that is the first one that is executed and also the one that immediately fails.
    My setDebug C function is defined as follow in BitmapImpl.c
    #include <time.h>
    #include <stdio.h>
    #include <limits.h>
    #include <fcntl.h>
    #include <jni.h>
    #include <math.h>
    #include <errno.h>
    #include "Bitmap.h"
    #include "data.h"
    jint debug = 0;
    jint statistics = 1;
    JNIEXPORT void JNICALL Java_Bitmap_setDebug
    (JNIEnv *jenv, jobject jo, jint d, jint s)
    debug = d;
    statistics = s;
    My libBitmapImpl.so file is compiled using the following Makefile and using GNU gcc:
    JAVAPATH=$(JAVAINCLUDEPATH)
    LMACRO=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DSOLARIS
    CSOURCE=BitmapImpl.c
    all:
    gcc -O3 -G $(LMACRO) -I$(JAVAPATH) -I$(JAVAPATH)/solaris \
    $(CSOURCE) -o libBitmapImpl.so
    It is still a total mystory why the application fails. I have tried it on a RedHat Linux machine and there it works fine. But not on Solaris. Only if I use the jdk1.1.8 but not a later one.
    Would really appreiciate some help!
    Best regards
    Lars

  • Using JNI with RMI/EJB.

    Hi,
    I am using JNI to interface with a c application.
    The problem is that c application is thread safe.
    Since i need to use this interface from RMI/EJB,
    multiple calls will be made simultaneosly on the
    c application.
    Will anyone tell me how do i handle this scenario?
    Thanks in Advance.
    Robin

    Is the ejb expect immediate result from the c application?
    If yes, I don't know. Perhaps you need to redesign your business logic so it will not expect immediate result from c.
    If no, then make a layer between the ejb and c. The layer would be message queuer application with JMS receiver. EJB will send JMS to the JMS receiver when it needs to execute c. You can queue the message so c application is executed without overlap. If the EJB expect the result from c, then the queuer can send it back using JMS.

  • Using JNI with weblogic JSP & Servlets

    I want to use native libraries from JSP and Servlets.
              Everything works fine befire redeploying.
              After redeploying there is an error:
              Servlet failed with Exception
              java.lang.UnsatisfiedLinkError: Native Library D:\WINNT\system32\XXXX.dll
              already loaded in another classloader
              at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1346)
              at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
              at java.lang.Runtime.loadLibrary0(Runtime.java:749)
              at java.lang.System.loadLibrary(System.java:820)
              at HelloWorld.<clinit>(HelloWorld.java:9)
              at NativeTestServlet.doGet(NativeTestServlet.java:31)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :208)
              at
              weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
              ntext.java:1127)
              at
              weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
              :1529)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              Can anybody solve it?
              Best wishes, Oleg.
              

    Java will not allow us to reload any class that is dependent on a native
              library. I suggest that any classes that depend on native code should be
              put in the system classpath. If you change these classes or the native
              library you will need to restart your server.
              Sam
              "Jennifer Yin" <[email protected]> wrote in message
              news:[email protected]...
              > Oleg-
              >
              > I'm having the exact same problem and was wondering how you fixed it. I
              ran
              > javah -jni <classname> to verify the correct method call and have also
              verified
              > that the library file is included in the system path.
              >
              > Any other suggestions?
              >
              > Jennifer
              >
              > Oleg wrote:
              >
              > > I want to use native libraries from JSP and Servlets.
              > > Everything works fine befire redeploying.
              > > After redeploying there is an error:
              > >
              > > Servlet failed with Exception
              > > java.lang.UnsatisfiedLinkError: Native Library
              D:\WINNT\system32\XXXX.dll
              > > already loaded in another classloader
              > > at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1346)
              > > at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
              > > at java.lang.Runtime.loadLibrary0(Runtime.java:749)
              > > at java.lang.System.loadLibrary(System.java:820)
              > > at HelloWorld.<clinit>(HelloWorld.java:9)
              > > at NativeTestServlet.doGet(NativeTestServlet.java:31)
              > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              > > at
              > >
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              > > :208)
              > > at
              > >
              weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
              > > ntext.java:1127)
              > > at
              > >
              weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
              > > :1529)
              > > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              > > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              > > >
              > >
              > > Can anybody solve it?
              > >
              > > Best wishes, Oleg.
              >
              

  • JNI with GCC

    I use java1.4.2_01 on a win98 (don't ask) machine.
    I am trying to run an "hello world" app with the method in C. The code is identical to that given here, http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html.
    My code works, if the .dll is generated instead with a colleague's Microsoft Visual compiler. I am asking, then, if there are known issues with using Cygwin and GCC 3.3.1cygming to generate the .dll. This is my commandline (prettified here) when running gcc:
    BASH-2.05b$ gcc -mno-cygwin -shared
    -I/c/j2sdk1.4.2_01/include
    -I/c/j2sdk1.4.2_01/include/win32
    -o hello.dll hello.cI have hex-viewed the .dll thus generated and found that it is actually a .dll (as opposed to an .so), but I don't have the reverse-engineering skills to find out anything more.
    Oh yes, the Java error is at run-time when the .display() method is called and is:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: test
            at TimTest.test(Native Method)
            at TimTest.main(TimTest.java:10)

    I am a little confused.
    You say that "extern C" should solve the problem. Am I correct in inferring that if I wrote C (not C++) code and compiled it as C code, this should never have come up?
    If I am correct there, then I would agree that the compiler might be `broken', or at least awkward. (As I had the same problem with JNI when I C-compiled C code.)
    If I'm not correct, please explain why "extern C" should produce no-mangling behavior. (my current understanding is that "extern C" is a directive saying "Treat the enclosed as C code.")
    Thanks.

  • JNI with Visual C++

    Hi,
    I am a newbie. I have a code using Visual C++ with integrated libraries. Can I interface it with Java ?
    Regards,
    D. Anand Kumar

    Hi,
    I can explain more on the question. I would like to write a program in Java which calls a native method that's described in a C++ program.
    Sample.java
    public class Sample
         static
              System.loadLibrary("Sample");
         // A native method that receives nothing and returns void
         private native void test();
         public static void main(String[] args)
              new Sample().test(); // invoke the native method
    Sample.cpp
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    void test() // native function
    // function definition
    I compiled and builded the Sample.cpp in a Visual C++ environment into a .dll. Now I tried to execute the java program with this dll and it said it could not find dependent libraries. I tried the following too.
    #include <jni.h>
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    JNIEXPORT void JNICALL Java_RUI_test(JNIEnv *env, jobject thisObj)
    //code
    I added additional dependencies to the program to include the jni header from JAVA_HOME/include and JAVA_HOME/include/Win32. I builded a dll and tried to execute the java code and hit again at the same error "Unsatisfied Link Error : Cant find dependent libraries".

  • JNI with rasapi32.Lib  (Dial Up Program)

    I am writting a dialup program on JAVA, using JNI of a C++ code.
    I included the header "ras.h" and i need to link the library named "RASAPI32.LIB" to compile the C++ code.
    and i found that i need to type this to Generate the dll file.
    cl -Ic:\java\include -Ic:\java\include\win32 -MD -LD dialup.cpp -Fedialup.dll -link RASAPI32.LIB
    (am i right?? as if i don't use "/link" i got an link error
    Is that the dll file i create included also the lib file? )
    after successfully generated the dll file. and then i run java dialup (i got error.. during the line i call the function in the dll. (error go out after the system.loadLibrary("dialup"); )
    I got UnsatisfiedLinkError at the line "new dialup().DialUp();" the only line in main function.
    Please help me smart programmers..... THX!
    also any care need to be taken when "JNI used with *.Lib & *.dll"

    Hi,
    I'm sorry, but i didn't understand very well.
    It seems that you made a program to dial to the internet, automaticaly, throw modem. If is that, please tell me more, how do you do that?
    Thanks in advance,
    Liliana

  • Using JNI with Visual C++!! kIND OF URGENT

    Hi PPL,
    I am trying to interface c++ programs compiled using the g++ compiler with JNI using Visual C++, Visual C++ for some reason is not able to locate pair and map header files, so i used the header file utility.h, but the problem is changing the g++ compiled code which use pair and map.h extensively, any ideas how i can do this.

    I don't see anything in this that suggests it has anything to do with java.
    So you might try posting to a VC++ list/board or a gnu(g++?) list/board.

  • JNI with VC++

    Hi Guys,
    I am new to JNI. I'd like to know if JNI works fine with VC++. If they can work together, should I follow the same process as described in JNI doc at java.sun web site ? Or there are some special steps I need to take to make this work ?
    thanks/

    Hi Guys,
    I am new to JNI. I'd like to know if JNI works fine
    with VC++. Yes.
    If they can work together, should I follow
    the same process as described in JNI doc at java.sun
    web site ? No idea.
    You use the javah generated headers along with JNI.h to create your code.
    Then you build a dll.

  • JNI with EJB

    Hi,
    I am planning to have EJB's use JNI functions developed inhouse, EJB specs do
    not recommend using JNI, please let me know. If Weblogic provides any speciufic
    features towards the same.
    Srinivas

    Is the ejb expect immediate result from the c application?
    If yes, I don't know. Perhaps you need to redesign your business logic so it will not expect immediate result from c.
    If no, then make a layer between the ejb and c. The layer would be message queuer application with JMS receiver. EJB will send JMS to the JMS receiver when it needs to execute c. You can queue the message so c application is executed without overlap. If the EJB expect the result from c, then the queuer can send it back using JMS.

Maybe you are looking for