Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6568063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:24:39+00:00 2026-05-25T14:24:39+00:00

I have a JAVA function which makes a call to C function through JNI

  • 0

I have a JAVA function which makes a call to C function through JNI .
My Java Function :

  char details= 'd';
        char reg_code='r';
        char[] reg_chal ={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x01,0x02,0x03,0x04,0x05,0x06} ;
        char[] aid = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x01,0x02,0x03,0x04,0x05,0x06}; 
        RegisterInfo regInfo = new RegisterInfo( reg_chal,aid);

        res = nativeLib.reg(regInfo, details, reg_code);

Now my C File which contains JNI stuff .. Actually i’m sending registerInfo object to JNI. Register Info class contains some char arrays. I want to assign the value of the char arrays to my C structure : reg_info_t:

#define DEBUG_TAG "NDK_NativeLib"
#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, __VA_ARGS__)

typedef struct{

    unsigned char reg_chal[12];
    unsigned char aid[12];
}reg_info_t;

JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_reg(JNIEnv *env,jclass obj,jobject info ,jchar details,jchar reg_code)
    {
        reg_info_t regInfo;
        jclass clazz;
        jfieldID fid;
        jmethodID mid;

        jint status =0; 

          LOGD("NDK:LC: [%s]", "JNI Function call started");

        clazz = (*env)->GetObjectClass(env, info);
        if (0 == clazz)
        {
            printf("GetObjectClass returned 0\n");
            return(-1);
        }

        jstring  reg_chal= (*env)->NewStringUTF(env,regInfo.reg_chal);
        fid = (*env)->GetFieldID(env,clazz,"reg_chal","Ljava/lang/String;");
        (*env)->SetObjectField(env,info,fid,reg_chal);
        LOGD("NDK:LC: [%s]", reg_chal);




         return status; 


}

RegisterInfo.java

public class RegisterInfo {  
   private char[] reg_chal  ;
   private char[] aid; 

   public RegisterInfo(char[] reg_chal,char[] aid) {
        super();         
        this.reg_chal = reg_chal;
        this.aid = aid;
   }
}

Now when i run the Code i get the error :

09-14 10:14:19.536: WARN/dalvikvm(666): **JNI WARNING: illegal start byte 0xf0**
09-14 10:14:19.536: WARN/dalvikvm(666):              string: '�ѯ$ԯ�'
09-14 10:14:19.536: WARN/dalvikvm(666):              in Lcom/marakana/NativeLib;.reg (Lcom/marakana/RegisterInfo;CC)I (NewStringUTF)

I think i am making some error in conversions between string,char[] and objects assigning. Can you please help me. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:24:40+00:00Added an answer on May 25, 2026 at 2:24 pm

    check this link for char[]

    jchar   NewCharArray
            GetCharArrayElements
            GetCharArrayRegion/SetCharArrayRegion
            ReleaseCharArrayElements
    

    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jnistring.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have system here that uses Java JNI to call a function in a
I have an application which makes use of JNA to call functions from a
I have a Java function which can take variable number of parameters and in
I have a java script function that i have called on body load mousemove()
I have a problem using the Java search function in Eclipse on a particular
I want to have a java app running, using a function/method (with as little
I have a calc function in java script that takes three integer parameters, following
I have noticed in Java that you can have a function with object... as
In my Java code I have function that gets file from the client in
I have a User Defined Function (UDF) written in Java to parse lines in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.