• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

My first JNI project

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic