array of strings in JNI

This is a discussion on array of strings in JNI within the C Programming forums, part of the General Programming Boards category; I know this is a JAVA thing but Im having issues with the C portion of the code. I know ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    array of strings in JNI

    I know this is a JAVA thing but Im having issues with the C portion of the code. I know there isnt a jStringarray type of or anything but I was trying to get an array of strings to pass into the C code for a simple example does anyone have any ideas

    Code:
    #include <jni.h>
    #include <stdio.h>
    #include "HelloWorld.h"
    
    JNIEXPORT void JNICALL
    Java_HelloWorld_print
    (JNIEnv *env, jobject obj, jstring javaString, jcharArray arr)
    {
    	jchar* buf;
    	jint i =0;
    
    	const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
    	printf("%s\n", nativeString);
    
    	buf = (*env)->GetCharArrayElements(env, arr, NULL);
    	if (buf == NULL) {
    		return 0; /* exception occurred */
    	}
    	for(i =0; i < 5; i++){
    		printf("%s\n",buf[i]);
    	}	
    
    
    	printf("Hello World!\n");
    	(*env)->ReleaseStringUTFChars(env, javaString, nativeString);
    	(*env)->ReleaseCharArrayElements(env, arr, buf, 0);
    	return;
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    No clue about Java (so I could be totally wrong), but this line looks suspicious
    Code:
    buf = (*env)->GetCharArrayElements(env, arr, NULL);
    Shouldn't it be
    Code:
    buf = (*env).GetCharArrayElements(env, arr, NULL);

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    No that part is fine because the env is a struct i think in jni.h and most of the examples using env function calls use the ->. The code i posted is C i already i java code that should be right but My c code isnt work
    Last edited by kiros88; 07-21-2010 at 01:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matching of names in 2d array of strings...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-25-2009, 10:59 AM
  2. intializing an array of strings
    By doubty in forum C Programming
    Replies: 4
    Last Post: 06-19-2009, 01:59 PM
  3. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  4. Build an array of strings dynamically
    By Nazgulled in forum C Programming
    Replies: 29
    Last Post: 04-07-2007, 10:35 PM
  5. Array of strings in C
    By szill in forum C Programming
    Replies: 10
    Last Post: 02-22-2005, 05:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21