?
Solved

JNI Starter

Posted on 2003-03-08
3
Medium Priority
?
700 Views
Last Modified: 2013-11-23
I compile the code below, but got this error.
how can i solve it...? I use VC++ to compile it...
please..
//Code
/* ReturnArray.C */
#include <jni.h>
#include "ArrayHandler.h"
JNIEXPORT jobjectArray JNICALL Java_ArrayHandler_returnArray
     (JNIEnv *env, jobject jobj){
     jobjectArray ret;
     int i;
     char *message[5]= {"first", "second", "third", "fourth", "fifth"};
     ret = (jobjectArray)env->NewObjectArray(5,
                    env->FindClass("java/lang/String"),
                          env->NewStringUTF("") );
     for(i=0;i<5;i++) {
        env->SetObjectArrayElement(ret,i,env->NewStringUTF(message[i]));
     }
     return(ret);
}

//Error
error C2223: left of '->NewObjectArray' must point to struct/union
error C2223: left of '->FindClass' must point to struct/union
error C2223: left of '->NewStringUTF' must point to struct/union
error C2223: left of '->SetObjectArrayElement' must point to struct/union
error C2223: left of '->NewStringUTF' must point to struct/union
0
Comment
Question by:cheng_koala
  • 2
3 Comments
 

Accepted Solution

by:
ravi_srch earned 90 total points
ID: 8098374
The solution to your problem is:---

Rewrite all the error statements as follows:

Convert
        env->FindClass("java/lang/String")
to      (*env)->FindClass(env,"java/lang/String")

That means you should use pointer of an env variable and place an extra first parameter 'env' in all the statements.
0
 

Author Comment

by:cheng_koala
ID: 8100567
I tried your method, but still got the same error
is it VC++ problem or it's setting problem?
0
 

Expert Comment

by:ravi_srch
ID: 8104536
Did you write the program this way:-

/* ReturnArray.C */
#include <jni.h>
#include "ArrayHandler.h"
JNIEXPORT jobjectArray JNICALL Java_ArrayHandler_returnArray
    (JNIEnv *env, jobject jobj){
    jobjectArray ret;
    int i;
    char *message[5]= {"first", "second", "third", "fourth", "fifth"};
    ret = (jobjectArray)(*env)->NewObjectArray(env,5,
                   (*env)->FindClass(env,"java/lang/String"),
                         (*env)->NewStringUTF(env,"") );
    for(i=0;i<5;i++) {
       (*env)->SetObjectArrayElement(env,ret,i,(*env)->NewStringUTF(env,message[i]));
    }
    return(ret);
}

If you have done this then go to command prompt and type as follows:-
cl -LD ReturnArray.c -Fe(dllname.dll)
dllname.dll should be replaced with your required dll file.
This should atleast work as i handled the same type of problem in my project.

This is not at all a VC++ problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month9 days, 14 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question