T
TsanChung
How to fix the error in
ret = (*env)->NewStringUTF(env, newstring);
C++ on solaris 10?
# CC -Kpic -G -o libfoo.so -I/usr/java/include -I/usr/java/include/
solaris foo.cpp -z text
"foo.cpp", line 26: Error: Pointer type needed instead of JNIEnv_.
1 Error(s) detected.
foo.cpp:
#include <algorithm>
#include <jni.h>
#include "JNIFoo.h"
JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *env, jobject
obj)
{
int i;
int ds_ret;
char* newstring;
jstring ret = 0;
newstring = (char*)new char[30];
if(newstring == NULL)
{
return ret;
}
std::fill(newstring, newstring + 30, 0);
newstring = (char *) "foo: Test program of JNI.\n";
ret = (*env)->NewStringUTF(env, newstring);
delete [] newstring;
return ret;
}
JNIFoo.java:
public class JNIFoo {
public native String nativeFoo();
static {
System.loadLibrary("foo");
}
public void print () {
String str = nativeFoo();
System.out.println(str);
}
public static void main(String[] args) {
(new JNIFoo()).print();
return;
}
}
# javac JNIFoo.java
# javah -jni JNIFoo
ret = (*env)->NewStringUTF(env, newstring);
C++ on solaris 10?
# CC -Kpic -G -o libfoo.so -I/usr/java/include -I/usr/java/include/
solaris foo.cpp -z text
"foo.cpp", line 26: Error: Pointer type needed instead of JNIEnv_.
1 Error(s) detected.
foo.cpp:
#include <algorithm>
#include <jni.h>
#include "JNIFoo.h"
JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *env, jobject
obj)
{
int i;
int ds_ret;
char* newstring;
jstring ret = 0;
newstring = (char*)new char[30];
if(newstring == NULL)
{
return ret;
}
std::fill(newstring, newstring + 30, 0);
newstring = (char *) "foo: Test program of JNI.\n";
ret = (*env)->NewStringUTF(env, newstring);
delete [] newstring;
return ret;
}
JNIFoo.java:
public class JNIFoo {
public native String nativeFoo();
static {
System.loadLibrary("foo");
}
public void print () {
String str = nativeFoo();
System.out.println(str);
}
public static void main(String[] args) {
(new JNIFoo()).print();
return;
}
}
# javac JNIFoo.java
# javah -jni JNIFoo