Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

My first JNI project  RSS feed

 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm experimenting with JNI, and I am getting stuck with my C++ compiler...can someone comment on this error that I'm getting?

Here's the function definition:

JNIEXPORT jboolean JNICALL Java_InputRecord_getData(JNIEnv *env, jobject obj)
{
jclass cls = (*env)->GetObjectClass(env, obj);
jfieldID fid;
jstring jstr;
...

which gives me the following error at the line with the "jclass" def:

error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'


I'm clueless.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The C++ syntax is a little different -- it's simpler. You don't need the (*) or the first "env" parameter for any JNI method:

jclass cls = env->GetObjectClass(obj);

There are some "#ifdef __cplusplus" macros in jni.h and friends to make this work.
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I have a little spare time, now, so let me just post what I'm trying to do, and maybe someone can give some suggestions before I dive into it. I have a datafile on disk, and it's binary, and I also have a STRUCT in C that corresponds to the structure of a record in the file. The file can contain from one to many records. I want to read in all the records and have access to them in my java program. I have C++ code to make a linked list out of the data, so my next step is to design a java class that mimics the STRUCT, and then pass all the data in the linked list via JNI. The STRUCT is a mix of primitives and arrays (single and multi-dimensional) but I I could probably get by ignoring the multidimensional arrays because I don't really need that data. I will need some linar arrays, though. So I guess what I think I need is a native method that does this:

1. Instantiates an object representing a record
2. Populates the object from the current element in the C++ linked list
3. Puts the object in an ArrayList
4. Moves to the next record in the linked list and goes back to step 1 if there are more elements.
5. Returns the ArrayList, or returns nothing and simply populates the ArrayList by reference.

Does this seem like a reasonable project to undertake with JNI? Something I can crank out in a weekend, I hope.

Kindly,

Chris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!