Re: Java jni: What's Wrong here?

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 29 Jan 2011 11:54:30 -0600

For those on the list interested in jni, Sina's question about the 
function retruning NULL was the key. I fixed that. Then the Java program 
threw an index out of bounds exception when the native method returned, 
but the method completed processing. After a little more cogitation i 
fixed that also. Now the translate subcommand in BrailleBlaster works. 
Next up is the emboss subcommand.

John

On Sat, Jan 29, 2011 at 11:29:14AM -0500, Sina Bahram wrote:
> Are you positive that:
> 
>   curObj = (*env)->GetObjectArrayElement (env, args, index);
> 
> will never return null?
> 
> Take care,
> Sina
> 
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx 
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of John J. Boyer
> Sent: Saturday, January 29, 2011 4:36 AM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Java jni: What's Wrong here?
> 
> One of the functgions in my Java bindings for liblouisutdml (Which will 
> be used in BrailleBlaster) requires a variable number of arguments. The 
> native method diclaration handles this with String[] The C function gets 
> a jObjectArray when it is called. The function which I am pasting below 
> is supposed to get each argument in turn according to the value of the 
> index parameter. It produces a segmentation fault. I think the problem 
> is in the line that attempts to procuce a C character string from the 
> Jobject. Suggestions? Thanks.
> 
> JNIEXPORT const jbyte *JNICALL
> getArg (JNIEnv * env, jobject this, jobjectArray args, jint index)
> {
>   static jobject curObj = NULL;
>   static const jbyte *curArg = NULL;
>   if (args == NULL)
>     return NULL;
>   if (curObj != NULL || index == -1)
>     {
>       if (curArg != NULL)
>       (*env)->ReleaseStringUTFChars (env, curObj, curArg);
>       curArg = NULL;
>       curObj = NULL;
>     }
>   curObj = (*env)->GetObjectArrayElement (env, args, index);
>   curArg = (*env)->GetStringUTFChars (env, curObj, NULL);
>   return curArg;
> }
> 
> -- 
> John J. Boyer; President, Chief Software Developer
> Abilitiessoft, Inc.
> http://www.abilitiessoft.com
> Madison, Wisconsin USA
> Developing software for people with disabilities
> 
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
> 
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind

-- 
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: