Exception JNI (Ljava/lang/String;)Ljava/lang/String;

I have made a little program in java that accepts a string as a user input. Now i have made a dll writing its code in Visual C++. when i run my program from netbeans it displays this exception.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Prompt.getLine(Ljava/lang/String;)Ljava/lang/String;
        at Prompt.getLine(Native Method)
        at Prompt.main(Prompt.java:19)

What problem is this. Need Help. Thanks

This is java code

public class Prompt {

    /**
     * @param args the command line arguments
     */
    private native String getLine(String prompt);
    public static void main(String[] args) {
        // TODO code application logic here
        Prompt p = new Prompt();
        String input = p.getLine("Type a line:");
        System.out.println("User Typed:" + input);
    }
    static {
        System.loadLibrary("Prompt");
        //System.load("C:/Program Files/Java/jdk1.6.0/bin/Prompt.dll");
    }
}

and this is C++ Code

#include "stdafx.h"
#include "jni.h"
#include "jni_md.h"

JNIEXPORT jstring JNICALL Java_Prompt_getLine(JNIEnv *env, jobject obj, jstring prompt)
{
    char buf[128];
    const char *str;
    str = env->GetStringUTFChars(prompt,0);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    printf("%s", str);
    env->ReleaseStringUTFChars(prompt, str);
    /* We assume here that the user does not type more than
    * 127 characters */
    scanf("%s", buf);
    return env->NewStringUTF(buf);
}

Answers


@org.life.java....i got the problem and it was my mistake, i was not including the header file of java which is JNI style header file which is Prompt.h in c++, "#include "jni_md.h" this will be eliminated and included "Prompt.h" now it is working fine.


Need Your Help

use jQuery to access dom after angularjs finished loading the view

jquery angularjs

I am working on a project which I can't modify the angular scripts, however I was allowed to add my own jquery script, but the problem is angular still loading the view and because of that the elem...

When should and shouldn't you break away from OOP for speed/performance?

java android performance oop

In their developer articles for Android, Google states that you should usually declare public variables rather than private ones with getters and setters to enhance performance on embedded devices (I