The Artima Developer Community
Sponsored Link

Java Answers Forum
Need JNI help: adding jstrings to jobjectArray

1 reply on 1 page. Most recent reply: Oct 15, 2002 8:31 AM by Matt Senecal

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Matt Senecal

Posts: 2
Nickname: splatt
Registered: Oct, 2002

Need JNI help: adding jstrings to jobjectArray Posted: Oct 15, 2002 8:17 AM
Reply to this message Reply
Advertisement
I'm trying to add jstrings to a jobjectArray, but I keep getting ArrayStoreExceptions, and I can't figure out why.

The array is declared here:

jclass strArrCls = (*env)->FindClass(env, "[Ljava/lang/String;");
apiData = (*env)->NewObjectArray(env, 24, strArrCls, NULL);


The string I'm adding is a field from a C struct. The C struct is defined as:


#ifndef __APIPARAMS_H
#define __APIPARAMS_H

typedef struct
{
char *year;
} ApiParams;
#endif


I'm doing the conversion and add here:


jstring tempString;
tempString = (*env)->NewStringUTF(env, theParams->year);
(*env)->SetObjectArrayElement(env, apiData, 0, tempString);


And that's where the exception is thrown. As far as I can tell, this should work. Am I missing something?


Matt Senecal

Posts: 2
Nickname: splatt
Registered: Oct, 2002

Got it! Posted: Oct 15, 2002 8:31 AM
Reply to this message Reply
This goes under the "dumb mistake" category. I was declaring the array to be:

jclass strArrCls = (*env)->FindClass(env, "[Ljava/lang/String;");

Which is an array of String arrays. Oops! What I wanted was an array of Strings:

jclass strArrCls = (*env)->FindClass(env, "Ljava/lang/String;");

Flat View: This topic has 1 reply on 1 page
Topic: Numbers conversion Previous Topic   Next Topic Topic: how to import a jar file

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use