JNI sample problem

Hi, I am trying to make a sample native method to work but not able till now. I need help to understand what I am doing wrong.
This is the example I am following : http://netbeans.org/kb/docs/cnd/beginning-jni-linux.html
The example is for linux, but I am using windows XP ( In the part of including directories I add win32 from java folder, except linux - I hope this is not the problem).
I do everything from the example good, build without errors, except the last build. It gives me this message:
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: jnidemojava.Main.nativePrint()V
        at jnidemojava.Main.nativePrint(Native Method)
        at jnidemojava.Main.main(Main.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)and this is the code in my main method (done as in the example)
I am using Netbeans IDE 6.9.1
Please, every help will be appreciated. I am stuck with this samples, try about ten different samples from the net, and still have not been made one of them working ... It is important for me to make one of them working because I am new in JNI and reading something like book about it but in the book everything is done in eclipse and to continue with the reading I have to understand how to make the samples there in NetBeans IDE.
Thanks in advance.
EDIT: I was not given to extract the code. I message tells my : " Sorry, this content is not allowed " ... I will try to past it somehow...
Edited by: gotqn on Feb 27, 2011 2:35 PM
Edited by: gotqn on Feb 27, 2011 2:36 PM

jshell, thanks for the answers, I understand that you do not want to click on links that may make to go to unsecured areas in the net ... It is a kind of insulting because I have just wanted to be helped, not to the something bad to people I do not know. Anyway, this is your right and I respect it.
It is very useless for me that I am not able to post my code and at the same time I am not said what is wrong with it. My code is not something big, we are talking about my first Java Native Interface program. It includes only few lines.
I really need help, so I will try to post anything it is possible.
This is part of java class main. I am not able to past the static load method, so I have to describe it: "I am adding the path way in the project VM options filed and I use load library adding only the name of the object without its extension."
public static void main(String[] args) {
        new Main().nativePrint();
    private native void nativePrint();This is my header file, that has been generated and add into the C/C++ library project:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class helloworld_Main */
#ifndef _Included_helloworld_Main
#define _Included_helloworld_Main
#ifdef __cplusplus
extern "C" {
#endif
* Class:     helloworld_Main
* Method:    nativePrint
* Signature: ()V
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint
  (JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endifThis is the source file and the native method:
#include <jni.h>
#include <stdio.h>
#include "Main.h"
JNIEXPORT void JNICALL Java_jnidemojava_Main_nativePrint
        (JNIEnv *env, jobject obj)
    printf("\nHello World from C\n");
}Edited by: gotqn on Mar 1, 2011 2:21 AM
Edited by: gotqn on Mar 1, 2011 2:24 AM
Edited by: gotqn on Mar 1, 2011 2:25 AM

Similar Messages

  • EXS Sampler Problems any one Help Help Help

    I Have recently been having loads of problems with my sampler instruments. When I click on some of them they take a while to load I have used the Project Manager in Logic Pro 7.1.1 to scan and that used to work but now no matter what I do in it whether doing an expanded scan or a selected scan or designated selected paths to scan it doesn't seem to make any difference. I have trashed the PM Prefs even the Logic Prefs even trashed logic and put on a fresh install.
    I recently in a desperate bid downloaded the demo of EXs Manager from Redmatica to re link my samples with the EXS interments after doing a little song and dance it came back with a great marketing ploy of having scanned so many instrument's it realised that I had more samples than the demo could handle to re-link the whole lot would need the full version which I will need to get at some point just to see whether it can do what it proclaims on the box.
    I am getting an error message when trying to load a few samples which reads 'Logical end-of -file reached during read operation Result code=-39'
    Can anyone tell me what this means

    I haven't had that problem, but my gut is telling me you have a bad drive or corrupt data on that drive. I'd run disk repair, and then if that passes run Disk Warrior or something like it to verify your data.
    EXS Manager works great, but it doesn't make samples load faster in my experience. EXS manager is more file management than anything...helps weed out unused samples and tidy up the organization.

  • JNI & thread problem

    Folks,
    I am using JNI to access WIA (Windows Image Acquisition) functionality under MS Windows XP. WIA consists of a bunch of COM interfaces. I have several native functions in a single dll, with a limited number of static variables stored in the dll between calls. This all works fine as long as long as the calls occur from the same java thread, but not if a new thread is created for some of the calls. I.e., this works:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    but this does not:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    (new Thread() {
    public void run() {               
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    }).start();
    Here, initializeWIA() and transferJPGNative() are the native methods. What happens in the second case is that transferJPGNative fails in one of the COM methods (not the first COM method it calls). The COM method returns an HRESULT indicating an error (509) which I can't find using any of the usual MS error look-up mechanisms. (Admittedly I am not the world's greatest Windows programmer...)
    Anyway, any suggestions would be much appreciated. I have found some issues regarding JNI and threads in this forum's archives, but none of them seem to apply to quite this situation.

    As a guess this is just a windows threading problem.
    And with COM you have to do things differently (I believe) if there is more than one thread. You might not even be allowed to do it with for that particular API.
    It could also be that you are initializing things more than once. Or you need to initialize twice (two handles.)
    At any rate you could always fix it by making the java code only allow calls for a single thread.

  • Eyedropper Current Layer sampling problem.

    Using the "current layer" sampling setting for the eye dropper before I apply any top layer adjustments (adding a top layer with a different blending more or adding an adjustment layer) it works fine. When I use any adjustment layers or any layer that has a blending mode, it affects the way the eyedropper picks color especially when set to current layer.
    For instance, If I paint a new blank layer with random colors, I create a black and white adjustment layer on top of that one, I select the first color layer I go to pick a color using the eye dropper with the current layer sampling set, it picks a grey color (which is wrong). BUT!! if I open up the color picker with the color layer selected it picks the correct color. Now, if I delete the black and white adjustment layer, and I am back to only having the color layer, I then go to pick a color with current layer sampling still set, it chooses a grey color again?!?! There are no more layers on top of the original color layer I painted first, and yet it chooses a grey color?!?! I hope this makes sense, any ideas on why this is happening?
    I am working on Photoshop CS5 12.1 64bit

    I'm having the same problem in CS5.
    With current layer selected and a not visible layer of curves (contrast) and trying to pick from the current layer it picks as if the curves layer was visible.
    I have attached 2 images: first trying to pick with the curves layer off (you can see that it's picking a black color where brown should be picked. Second one with the curves layer on.
    After restarting Photoshop every thing work fine again. So I have assumed that the problem is vinculated with the action done before:
    Duplicate image 2 times
    Gaussian blur of 6px to the first image
    Apply image of the gaussian (RGB channel) inverted in mode "Add", scale 2, displacement 0.
    And I create a group as you can see on the screen shots.
    http://www.youtube.com/watch?v=wh6eIyrzbt0&t=1m8s
    I can reproduce this issue every time I use this technique...

  • JSP/EJB sample-problem

    Hi,
    I'm having difficulties to get the Oracle JSP sample to wrok.
    I deployed the JSP App and also the StackDemo app and changed the envrionment variables as requested .
    But each time I try to use the DemoStack bean by submitting a 'create stack' I get the message :
    "The requested access method is not allowed for that object"
    Can anybody help me with this problem?
    Michel.

    Alex,
    I use OAS 4.0.8.1.
    I also reloaded the application after deployment.
    I used a clinet snippet that is compiled in JDevelope 3.0 and I run it from there .
    It finds THE EJB , ic reated and deployed without giving any error messages. The problem rises the moment I try to use one of the functions of the remote interface of the EJB. In these functions I try to use functionality of viewObjects that are provided by a bussines component that I generated using JDeveloper 3.0.
    The wrb log file mentions a 'null pointer exeption'.
    I think that I do something wrong when initializing the application module that wraps the business component, but I can't see what is wrong.
    This is the code I use in my EJB :
    String theAM = "EDMpackage.EDMAppModule";
    ApplicationModule root = null;
    String sessionDefName = ApplicationModule.DEFAULT_DEF_FULL_NAME;
    Hashtable env = new Hashtable(2);
    env.put(Context.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
    env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
    try
    Context ic = new InitialContext(env);
    ApplicationModuleHome home = (ApplicationModuleHome)ic.lookup(sessionDefName);
    root = home.create();
    catch(Exception e)
    e.printStackTrace();
    localAppMod = root.createApplicationModule( "EDMAppMod",theAM );
    This works fine , but when I try to get a ViewObject through the localAppMod, I get the error. So I think I am wrong somewhere here.
    Michel.

  • Adobe Acrobat XI SDK Samples problem

    I am having problems building and running SDK samples.
    When built “out of the box”, the WebLinkDemo fails while getting HFT for AcroColor.
    After some googling, I found Adobe Acrobat XI SDK Release Notes:
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/release- notes-acrobatxisdk.PDF
    Following their directions:
    deleted
    /D PI_ACROCOLOR_VERSION=0x00060000
    inserted
    /D READER_PLUGIN
    WebLinkDemo builds OK, but required SnippetRunner fails to compile with multiple errors like:
    >c:\code\adobe\acrobat xi sdk\samples\snippetrunner\sources\snippets\shared\acetranspdetextcolorsnip.cpp(60): error C2065: 'PDEContentGetNumElemsSELPROTO' : undeclared identifier
    SELPROTO seems to be the commot suffix.
    Any suggestions?
    Thank you!

    Perhaps a little more context. You should understand that the Acrobat SDK is a tool for encouraging people to buy Acrobat - especially the consumers of plug-ins.
    Reader plug-ins can be made, subject to technical limitations, but Adobe do not especially like the lost sales of Acrobat this may represent.
    In addition to purchasing Acrobat, you will need to buy a Reader integration key, after negotatiation. Approval is not automatic!  There are also two scales of fees, one for regular Reader plug-ins and one for security related plug-ins, for which Adobe has a much higher fee and demands much more oversight.
    "How much does a Reader Integration key cost?
    Reader Integration keys are only available to strategic partners based on a negotiated price. If you are developing a digital rights management (DRM) Adobe Reader plug-in, the standard (non-DRM) RIKLA contract does not apply. Adobe does offer a DRM agreement specifically for developers building such Adobe Reader plug-ins. The current fee structure for the DRM RIKLA includes a $50,000 annual fee and a 5.5% revenue royalty."
    http://www.adobe.com/devnet/reader/ikla.html
    So, yes, to experiment with plug-ins, whether for Acrobat or eventually for Reader, please listen to what we are telling you and if you want to do this, buy Acrobat.

  • DI Server sample: problem with login

    Hi,
    I am studying the DI Server/WSClient sample and I try to connect with de DI Server to my company.
    When I try with the DI API, with the same username and passwords, servername etc..., it will succeed.
    When I use the DI Server it generates the following error for the sessionID:
    Error env:Receiver -1 General Error Login
    Because it is the sample delivered with SAP BO, I assume that there are people who examined this example.
    Does anyone know what I do wrong??
    I found that in administration->licence
    I select the tab Properties and select "DI-Server (DIS)"
    I see: Total Number = 2 and Available licence numbers = 2.
    Which means that the licences are not assigned to any user yet.
    When I select the Configuration tab and I select user manager, I see that I can select licences for professional user, SAP Addons and SDK Tools. But I can't assign a licence for the DIS. This could be te reason of the problem. The question is: How can I solve this??
    Greetz
    Eddy
    Message was edited by: Eddy Aper

    > Eddy,
    >
    > Please look at this link to another question and
    > answer in this forum that looks similar to the issue
    > that you are having.
    >
    > https://www.sdn.sap.com/sdn/collaboration.sdn?contentt
    > ype=url&content=https%3A//forums.sdn.sap.com/thread.js
    > pa%3FforumID%3D56%26threadID%3D33989%26messageID%3D342
    > 192%23342192
    >
    > Hope this helps,
    >
    > Eddy
    Eddy,
    i am having a similar problem with the DI server, but i can find the post that you have mentioned, it goes to a page moved screen and then back to the main page. Can you please advice how to fix the DI server Genreal Error issue.
    Thanks in advance
    Mitesh

  • Freshmen for JNI several problem  urgently

    hi,
    1.. I have created the Cpp file to implemement the native method but it seems that the native method can not complie rightly , it tells me follows
    error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    c:\program files\microsoft visual studio\vc98\include\jni.h(764) : see declaration of 'JNIEnv_'
    c:\users\wangyue\desktop\java_gui\beattrack 5.6 - ������_������_������������ 5.7\beattrack.cpp(202) : error C2227: left of '->GetByteArrayRegion' must point to class/struct/union
    then I use the c file to paste the same code, it can complie rightly , why? I really need my native method to complie rightly in Cpp file, how to solve it?
    2.I want to return a double, for the most simple way, I do the following
    #include "RealBeatTrack_BeatTrack.h"
    JNIEXPORT jdoubleArray JNICALL Java_playaudio_BeatTrack_BeatTrack
    (JNIEnv *env, jobject j, jbyteArray data)
         jdouble outdata[4]={1,2,3,4};
         return (*env)->NewDoubleArray(env, outdata);
    then in the java code, I difine a array to receive it,
    say double mydata[] = new double[4];
    mydata= BeatTrack(buffedata);
    but the java comlier tells me the Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space?
    anyone can help me?
    Thanks

    at least question 1 has been answered [ by AmitGee in this thread|http://forum.java.sun.com/thread.jspa?threadID=5302982&tstart=3]
    and question 2 is now obsolete, though I still have a new problem which I will post in a separate thread.
    Thomas

  • CRIO 9076 AI Sampling Problem

    Hi,
    I have a question about the NI 9223 samping rate in our cRIO 9076 system.
    Since we are hoping to samping at a rate up to 500K or 1M,  we are now using the user controlled I/O sampling.
    Right now, we are sampling at 500K (2us). But I got a tick count of 99 ticks (around 2.5us) for the sampling node only.
    Should I be expecting so many ticks for the sampling block? Did I do anything wrong?
    Thank you so much!
    Solved!
    Go to Solution.
    Attachments:
    problem.JPG ‏399 KB

    Hi hang-up,
    It looks like you are specifying the loop rate for the entire while loop you are in, and not just that one specific part of code.  Because you have your loop timer controlled by an front panel object, it is possible that the code compiled, but if you change the loop time to a low value, the code cannot complete in time.  I would suggest that you isolate the acquisition you are trying to do in it's own loop so that it can run at full speed.
    Additionally, in order to get the full MS/s acquisition, you are going to need to architect your acquisition.  I would encourage you to check out the example code in our Example Finder for the NI 9223 User Controlled II Compositionally for the best way to get these maximum acquisition rates.  Additionally, depending on how you are going to be exporting this data from the FPGA, your ART controller may not be able to handle a sustained MS/s throughput.
    To explicitly answer your question, I suspect that because you are trying to complete a large loop in a short amount of time, the FPGA cannot complete the task in time, so it defaults to a rate that can be better handled.  For the control you are looking for, I would encourage you to move your application over to the architecture found in the example project to get the behavior you are looking for.
    Ben N.
    Applications Engineering
    Certified LabVIEW Developer

  • Samples Problem (Channel disconnected)

    I am running Tomcat 6 and JRE 1.5, with FDS. Running the
    Dashboard sample is not a problem (except for a lack of heapspace
    in the JRE sometimes). However, the CRM sample is not working. I
    get the error "Channel disconnected" on the client side, and on the
    server side I am seeing a JRE error ... specifically a
    javax/transaction/SystemException throwable. The last entry in the
    stack trace is: java.lang.NoClassDefFoundError:
    javax/transaction/SystemException at
    flex.data.DataService.serviceMessage(DataService.java:305). I have
    installed JOTM JARs in the Tomcat common\lib directory, and created
    a "samples.xml" file in the conf\Catalina\localhost directory.
    I am new to Flex2 (and FDS), and I am also new to Tomcat. But
    I am really not trying to get too sophisticated right now. I am
    frustrated, and I appreciate any help that anyone can give me!
    All I really want to do is to create a simple application
    that communicates using RTMP to transport POJOs on the server side
    to AS classes on the client side. I have run the
    tutorial
    that Christophe Coenraets provided, and it works just fine. But
    when I try to build a test from scratch by installing Tomcat, FDS,
    JOTM (do I really need that piece?), and then creating the mxml,
    as, and class files I have problems. Which caused me to try the
    samples that come with FDS.
    As a side note ... there is a statement that memory for the
    JRE should be increased, but no specific instructions for
    increasing it. That's not my immediate problem with the CRM sample,
    and so I'll figure it out later.

    Just an update ... although I am not sure that anyone will
    ever see any of this:
    I reinstalled Tomcat, FDS, and JOTM. I actually put the JOTM
    JARs into the tomcat/lib directory, since I wasn't certain where
    Tomcat will look. I added the TransactionFactory element to
    tomcat/conf/context.xml. This entry specifies to Tomcat that the
    default transaction factory is JOTM. I also changed the heap size
    for the JVM, which I realized can be changed using the Tomcat
    configuration program shown in the Tomcat menu under the Windows
    Start Menu.
    I am still getting a "Channel disconnected" error when I
    attempt to update a value in the CRM sample application. The
    exception in the Tomcat window is:
    java.lang.ExceptionInInitializerError. This appears to be thrown in
    the constructor of the jotm Current class.
    Does anyone have any ideas? Or at least a similar problem?
    Thanks!

  • JNI Launcher Problem

    Hello,
    i have a problem, if i want to run as Titan JNI Launcher the followning Message occur:
    !ENTRY org.eclipse.titan.common 4 0 2015-07-08 16:28:11.135
    !MESSAGE JNI dynamic library could not be loaded.
    original message: no mctrjninative in java.library.path
    java.library.path = /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
    !STACK 1
    org.eclipse.core.runtime.CoreException: JNI dynamic library could not be loaded.
    original message: no mctrjninative in java.library.path
    Maybe the java.library.path is the problem but i cant find where i can change it.
    My path variable is JDKDIR := /usr/lib/jvm/java-7-openjdk-amd64 .
    Do you have any idea, how to solve this issue ?
    Best Regards
    Johannes

    jbruder@jbruder-VirtualBox:~$ java -XshowSettings:properties
    Property settings:
    awt.toolkit = sun.awt.X11.XToolkit
    file.encoding = UTF-8
    file.encoding.pkg = sun.io
    file.separator = /
    java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
    java.awt.printerjob = sun.print.PSPrinterJob
    java.class.path = .
    java.class.version = 51.0
    java.endorsed.dirs = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/endorsed
    java.ext.dirs = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext
    /usr/java/packages/lib/ext
    java.home = /usr/lib/jvm/java-7-openjdk-amd64/jre
    java.io.tmpdir = /tmp
    java.library.path =
    /home/jbruder/titan/Install/lib
    /usr/java/packages/lib/amd64
    /usr/lib/x86_64-linux-gnu/jni
    /lib/x86_64-linux-gnu
    /usr/lib/x86_64-linux-gnu
    /usr/lib/jni
    /lib
    /usr/lib
    java.runtime.name = OpenJDK Runtime Environment
    java.runtime.version = 1.7.0_79-b14
    java.specification.name = Java Platform API Specification
    java.specification.vendor = Oracle Corporation
    java.specification.version = 1.7
    java.vendor = Oracle Corporation
    java.vendor.url = http://java.oracle.com/
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    java.version = 1.7.0_79
    java.vm.info = mixed mode
    java.vm.name = OpenJDK 64-Bit Server VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Oracle Corporation
    java.vm.specification.version = 1.7
    java.vm.vendor = Oracle Corporation
    java.vm.version = 24.79-b02
    line.separator = \n
    os.arch = amd64
    os.name = Linux
    os.version = 3.19.0-22-generic
    path.separator = :
    sun.arch.data.model = 64
    sun.boot.class.path = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar
    /usr/lib/jvm/java-7-openjdk-amd64/jre/classes
    sun.boot.library.path = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64
    sun.cpu.endian = little
    sun.cpu.isalist =
    sun.io.unicode.encoding = UnicodeLittle
    sun.java.launcher = SUN_STANDARD
    sun.jnu.encoding = UTF-8
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    sun.os.patch.level = unknown
    user.country = DE
    user.dir = /home/jbruder
    user.home = /home/jbruder
    user.language = de
    user.name = jbruder
    user.timezone =

  • JNI CallVoidMethod problem.

    Hello all,
    I am learning JNI Language, and I have a CallVoidMethod problem.
    I get ERROR: The instruction at "0x6d494f54" referenced memory at "0x00000004". The memory could not be "read".
    Here is the code:
    <PRE>
    //========== Java Source =====
    class Test {
    private void javaMethod() {
    System.out.println("\n Java Method ");
    // Load Test.dll
    static {
    System.loadLibrary("Test");
    private native void create();
    public Test() {
         create();
    //========== C++ Source =========
    #include <jni.h>
    #include "Test.h"
    // Global
    JNIEnv *g_env;
    jobject g_obj;
    jmethodID g_mid;
    // JavaCallMethod
    void cMethod(JNIEnv *e, jobject o, jmethodID m) {
    e->CallVoidMethod(o,m);
    * Class: Test
    * Method: create
    * Signature: ()V
    JNIEXPORT void JNICALL Java_Test_create
    (JNIEnv *env, jobject obj) {
    g_env = env;
    g_obj = obj;
    jclass clazz = env->GetObjectClass(obj);
    g_mid = env->GetMethodID(clazz, "javaMethod", "()V");
    // ========== until here is all O.K. ============
    cMethod(g_env, g_obj, g_mid);
    // WndProc
    LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
    cMethod(g_env, g_obj, g_mid);
    // =========== ERROR =========
    // The instruction at "0x6d494f54" referenced memory at "0x00000004".
    // The memory could not be "read".
    </PRE>
    Sorry my English is not so well.
    Thanks for your help.

    Are you actually getting the windows callback, or are you sure the error is coming when you hit the first call to cMethod?

  • JNI wchar_t problem (unix platforms)

    Hi all,
    i have such kind of broblem on unix platforms. I have unicode string in JNI and when i create jstring and return it to java the string is not completed. So,
    wchar_t name[50] = L"Ob als Sch�ler";
    jstring objectName = NULL;
    len = wcslen(name);
    objectName = (*env)->NewString(env, name, len);
    return objectName;
    I receive in Java "Ob als". I receive warning when compile the c code, theat argument #2 is not compatible with prototype. This happened because the second parameter is unsigned short, and wchar_t, which i passed, is four bytes. How can i fix this problem with wide char string? Is it a good idea to convert wchar_t string to char string and after that to create NewStringUTF? I noticed that when the len is twice bigger i.e. len = 2*wcslen(name) the string which is created is full. Is it correct to use this function with twice more length?
    Thanks,
    Valentin

    The problem happens when the size of wchar_t mismatches the size of jchar. Under Linux, wchar_t has size 4 while jchar has size 2. Using the short-wchar option for GCC can surely set wchar_t to have size 2, but problems will occur with any library compiled without the option; this will include all standard libraries.
    I have successfully passed strings from Java to JNI using the following workaround. My solution worked with Linux x64, but there is no reason it won't work in 32 bits.
    Suppose we have a class with a getString native method returning a string from the C world, and a print method printing a string coming from Java using C' wprintf.
    Here is the code for the getString method:
    JNIEXPORT jstring JNICALL Java_TestJNI_getString
    (JNIEnv * env, jclass cls) {
       const wchar_t* str = L"Here is a quite long and useless string. Note that this even works with non-ASCII characters, like in Allô les élèves.";
       size_t len = wcslen(str);
       if (sizeof(wchar_t) != sizeof(jchar)) {
          // In Linux, we get there.
          // First, allocate a buffer for the string to pass to Java, not forgetting the \0
          jchar* str2 = (jchar*)malloc((len+1)*sizeof(jchar));
          int i;
          for (i = 0; i < len; i++)
             // This discards two bytes in str, but these should be 0 in UTF-16
    str2[i] = str[i];
    str2[len] = 0;
    // Now we have a compatible string!
    jstring js = (*env)->NewString(env, str2, len);
    // And we can free the buffer, to prevent memory leaks
    free(str2);
    return js;
    else
    // Under Windows, we don't need such a hack
    return (*env)->NewString(env, str, len);
    And now the code for print:JNIEXPORT void JNICALL Java_TestJNI_print
    (JNIEnv * env, jclass cls, jstring js) {
    const jchar* str = (*env)->GetStringChars(env, js, NULL);
    if (sizeof(wchar_t) != sizeof(jchar)) {
    // Size mismatch, so translate the string
    // Get the length using Java (strlen or wcslen should return the wrong length, or even segfault)
    jint len = (*env)->GetStringLength(env, js);
    // Allocate a buffer, not forgetting the \0 terminating character
    wchar_t* str2 = (wchar_t*)malloc((len+1)*sizeof(wchar_t));
    int i;
    for (i = 0; i < len; i++)
    str2[i] = str[i];
    str2[len] = 0;
    wprintf(L"%ls\n", str2);
    free(str2);
    else {
    // Under Windows, we don't need the hack
    wprintf(L"%ls\n", str);
    (*env)->ReleaseStringChars(env, js, str);

  • Adobe LiveCycle Designer Samples - problem

    Hello,
    i've just downloaded the DataImportExport.zip from
    http://partners.adobe.com/public/developer/livecycle/designer/index_samples.html
    and i have one question.
    Why i am unable to run first example: "Export Data: User to specify the file name" ?
    Does anyone have the same problem ? I have Reader 7.0.5.
    Also the third example works.
    Please help me !

    You need Acrobat, not Reader, to export data.
    Carl Young
    www.pdftrain.com

  • EXS 24 Sampler problems.

    I have just loaded Logic X onto a 27 inch i7 imac and have 32 gig of ram.
    I have always used homemade EXS 24 sample banks successfully on previous set ups Logic 8&9 - and have created new samples to use on the new supposedly more powerful Logic X using convert to sampler function.
    Playing one track of these samples come out fine, however when I have two or more sampler tracks playing togther, I seem to get a sort of crunch noise every now and again - as if the CPU or Ram is overloading.
    Does anyone have a solution for this please.
    Thank you !

    hi, again,
    sound like you are trying to do everything at once!!!
    even the beefiest macs will fold if you push this approach!!
    render some of you're VI's to audio, or freeze them.
    i have a very old machine but as long as i'm careful and PLAN everything, i have no trouble getting ~ 64- 96 stereo clips @ ~3min ea. running with fx at mixdown.
    also, audio clips allow you too inspect the timing, groove of the song and tighten/loosen it to taste in an accurate repeatable fashion.
    best, david r.

Maybe you are looking for