?
Solved

JNI Starter

Posted on 2003-03-08
3
Medium Priority
?
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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