The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

I encountered the same prolem and found an answer

Posted by Tina Sun on January 25, 2002 at 3:39 PM

> I am doing something very similar to what is right out of Rob Gordon's JNI book but I am getting compile errors. This should be a simple one for you guys. Please help.
> Thanks...

> Here's the code:

>
> #include
> #include
> #include
> #include "jni.h"
> #include "SAVI.H"
> #include "SAVITAG.H"
> #include "com_unisys_itv_JVendor.h"

>
> jobjectArray JNICALL Java_com_unisys_itv_JVendor_sIntReport(JNIEnv *env,
> jobject this,
> jint nx,
> jint report_format) {

>
> // Tag Data collected
> TagSet_t *tags;
> int i = 0;

> Savi_Code = Savi_Int_Report(nList[nx].id, &tags, report_format);

> if (Savi_Code == SAVI_OK) {

> // determine size of array to create
> jint arySz = (jint) tags->n_tags;
> // load the class of array elements with class loader
> jclass clazz = env->FindClass("com/unisys/itv/JSaviFullRpt");
> if (clazz == 0 ) {
> return NULL;
> }
> // create the array of Java JSaviFullRpt objects
> jobjectArray aryFullTagt = env->NewObjectArray(arySz, clazz, NULL);
> if (aryFullTagt == 0) {
> return NULL;
> }

> // create the field IDs so we can access the Java object's fields
> jfieldID fTagId_FID = env->GetFieldID(env, clazz, "tag_id", "I");

> // create the Java constructor method ID so it can be called
> jmethodID mid = env->GetMethodID(clazz, "", "()V");

> switch (report_format) {

> case FULL_REPORT:
> for (i = 0; i < tags->n_tags; i++) {
> // create the Java array element (call its no-args ctor)
> jobject thisJSaviFullRpt = env->NewObject(clazz, mid);
> env->SetObjectArrayElement(aryFullTagt, i, thisJSaviFullRpt);

> // set aryFullTagt.tag_id
> env->SetIntField(env, thisJSaviFullRpt, fTagId_FID,
> ((jint) tags->tag.FULL.tag_id));

> // delete the local reference created above
> env->DeleteLocalRef(thisJSaviFullRpt);
> }
> break;

> }

> // return the array created
> return aryFullTagt;
> }

> // report was not generated properly
> return NULL;
> }

>
> And here's the errors:

> error C2223: left of '->FindClass' must point to struct/union
> error C2275: 'jobjectArray' : illegal use of this type as an expression
> \jni.h(99) : see declaration of 'jobjectArray'
> error C2146: syntax error : missing ';' before identifier 'aryFullTagt'
> error C2065: 'aryFullTagt' : undeclared identifier
> error C2223: left of '->NewObjectArray' must point to struct/union
> error C2275: 'jfieldID' : illegal use of this type as an expression
> e:\itvclient\src_c\rwcommon\savi_dll\jni.h(118) : see declaration of 'jfieldID'

> error C2275: 'jmethodID' : illegal use of this type as an expression
> \jni.h(121) : see declaration of 'jmethodID'
> error C2146: syntax error : missing ';' before identifier 'mid'
> error C2065: 'mid' : undeclared identifier
> error C2223: left of '->GetMethodID' must point to struct/union

> error C2223: left of '->DeleteLocalRef' must point to struct/union
> warning C4047: 'return' : 'struct _jobject *' differs in levels of indirection from 'int '

> ... (more similar)

> Error executing cl.exe.

> It is like it is not finding or using the header files or using the wrong ones but I have checked to be sure the included jni.h and jni_md.h are up to date (from JBuilder5). I also made sure the class file used in FindClass is in the environment's classpath.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us