Converting jstring to char*

Hi,
I would like to convert a jstring (which is an argument in a method) to a C++ char*. How to do that?
I think it should be something like:
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv* env, jobject obj, jstring str)
char* text= ???;
Thank you for your answer :-)

const char * stringa = env->GetStringUTFChars(_jstringa,null);

Similar Messages

  • Convert jstring to char array or int array

    Hi all, please help with the following code. I've tested this code with hard coded char array and it works. Now I have to get the char array from parameter "param1" which is passed from Java.
    The following code compiled with error message:
    error C2223: left of '->GetStringUTFChars' must point to struct/union
    JNIEXPORT void JNICALL Java_DongleSet_DongleWrite(JNIEnv *env,jobject obj,jstring param1){
    char HaspBuffer[500]=(char)env->GetStringUTFChars(param1,NULL);
    int Service=MEMOHASP_WRITEBLOCK;
    int SeedCode=300;
    int LptNum=0;
    int Pass1=pass1;
    int Pass2=pass2;
    int p1=0;
    int p2=12;
    int p3=0;
    int p4=(int)HaspBuffer;
    hasp(Service,SeedCode,LptNum,Pass1,Pass2,&p1,&p2,&p3,&p4);
    I've tried this:char HaspBuffer[500]=env->GetStringUTFChars(param1,NULL);
    And this:char HaspBuffer[500]=(*env)->GetStringUTFChars(param1,NULL);
    All give me errors.
    Please help.

    char * HaspBuffer=(*env)->GetStringUTFChars(param1,NULL); When writing pure C, you have to supply the JNIEnv as first arg to every JNIEnv function pointer.char * HaspBuffer=(*env)->GetStringUTFChars(env, param1, NULL);Look here: http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jnistring.html

  • Converting jstring to char in c

    I'm trying to convert a jstring to const char (a pointer), but I keep getting an exception.
    is there some kind of defenition I'm missing????
    here's part of the code:
    jmethodID methID;
    jstring jstr;
    const char *str;
    /* Get a reference to obj2 class */
    jclass cls = (*env)->GetObjectClass (env, obj2);
    if (cls == NULL){
    return; /*return in case the object couldn't be found */
    methID = (*env)->GetMethodID (env, cls, "getPgmId", "()Ljava/lang/String;");
    jstr = (jstring) (*env) -> CallCharMethod(env, obj2, methID);
    if (jstr == NULL){
    printf (" \nthe result String is null \n");
    fflush(stdout);
    return;
    str = (char)(*env)->GetStringUTFChars (env, jstr, 0);

    your method signature shows that your method returns a string but you are using "CallCharMethod"...you should be using CallObjectMethod since a string in java is actually an object not a datatype.
    this is an example of getting a jstring and converting it to a char*. i need the char* so i do a strdup and release...
    jstring desc = (jstring)env->CallObjectMethod(obj, mid, failType);
    if(desc == NULL){
         cout << "desc == null" << endl;
         return (char*)errorHandler('c', JNI_NO_METHOD);
    char* cDesc = strdup(env->GetStringUTFChars(desc, 0));
    env->ReleaseStringUTFChars(desc, cDesc);

  • Converting "jstring" to "char *" in VC++

    Hello,
    I have a native method whose input parameter is a string. I used the below lines of code to get a char *. These code i got it from the JAVA TUTORIALS only.
    JNIEXPORT jint JNICALL Java_SpringDLL_createExtensionSpringDXF
    (JNIEnv *env, jobject obj, jstring jsprData)
    const char sprData = (env)->GetStringUTFChars(env, jsprData, 0);
    printf("%s", sprData );
    (*env)->ReleaseStringUTFChars(env, jsprData, sprData);
    I am using VC++ Application Wizard to generate the DLL.
    The error i am getting is :
    SpringDLL.cpp(72) : error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    C:\JDK1.3\INCLUDE\jni.h(746) : see declaration of 'JNIEnv_'
    SpringDLL.cpp(72) : error C2227: left of '->GetStringUTFChars' must point to class/struct/union
    SpringDLL.cpp(100) : error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    C:\JDK1.3\INCLUDE\jni.h(746) : see declaration of 'JNIEnv_'
    SpringDLL.cpp(100) : error C2227: left of '->ReleaseStringUTFChars' must point to class/struct/union
    Can anybody help me out how to get rid of this error. Please its an very urgent....
    if you can send me an email then please don't hesitate to send it to "[email protected]".
    Thanks,
    Patro

    The code from the tutorials id for C not C++. As you are using C++, use 'env' like this
        jclass     cls=env->GetObjectClass(obj);because when using C++ env is a pointer to an object.

  • Converting a 6 char string to date

    Please help..
    How can I convert a 6 char date (ddmmyy) to date format
    that can be passed as input to function module?

    Hi,
    Try FM,
    CONVERT_DATE_TO_INTERNAL
    Run this sample code,
    DATA:
      my_date(6) TYPE c VALUE '300708',
      w_date     TYPE sy-datum.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
      EXPORTING
        date_external                  = my_date
    *   ACCEPT_INITIAL_DATE            = ACCEPT_INITIAL_DATE
    IMPORTING
       date_internal                  = w_date
    EXCEPTIONS
       date_external_is_invalid       = 1.
    WRITE: w_date.
    Regards
    Adil

  • Converting int to char

    Hi!..
    I have a problem!...
    I need to convert integers to chars, but i`m using char(int)....
    So, only accept until ascii code 128..
    Please, What can I do?
    This is my code:
    Thanks!
    public Convert() {
    public static void main(String[] args) {
    Convert convert1 = new Convert();
    System.out.print(f_Transforma("ABCD"));
    public static String f_Transforma(String Password)
    int IntStrLong=Password.length();
    String StrResultado=new String();
    while (IntStrLong >=1)
    int tmpchar=(int)Password.charAt(IntStrLong-1); //valor ascii
    tmpchar=256-tmpchar+IntStrLong;
    String aChar = new Character((char)tmpchar).toString(); //ASCII code to String
    StrResultado=StrResultado+aChar;
    IntStrLong-=1;
    return (StrResultado);
    }

    I did what you told me and nothing happened...
    int tmpchar=(int)Password.charAt(IntStrLong-1); //valor ascii
    tmpchar=256-tmpchar+IntStrLong;
    tmpchar=tmpchar>>8;
    String aChar = new Character((char)tmpchar).toString(); //ASCII code to String

  • FM to convert double byte chars

    Hi All,
    Is there anyone know what are the function module to convert double-byte chars? Thanks.

    Seems like Blue Sky is not clear
    You want to convert what into what?
    Whats the purpose of this requirement, kindly give more details.
    Regards
    Karthik D

  • How to convert ASCII to CHAR?

    Hi, experts.
    Now I want to convert ASCII to CHAR, can you give me some methods? And I also want to know what's my ABAP Version.
    Thanks in advance!

    *After look so bad code that no work i did my own code, a gift for all you:*
    FORM CHARACTER_ASCII   using    p_letra
                                                 changing p_nro   type i.
    field-symbols: <n> type x.
    assign p_letra to <n> casting.
    move <n> to p_nro.
    ENDFORM.
    FORM ASCII_CHARACTER using    p_nro type i
                                               changing p_letra.
    DATA: c    TYPE c,
          x(4) TYPE x.
    FIELD-SYMBOLS: <fc>  TYPE c.
    x = p_nro.
    ASSIGN x to <fc> CASTING TYPE c.
    MOVE <fc>+1(1) to p_letra.
    ENDFORM.

  • Converting raw to char

    Hi SDN,
    I have to convert raw to char.
    data : lv_raw(16) type RAW.
    data : lv_char(16) type c.
    lv_raw = some value.
    i want to convert this value in lv_raw to lv_char in character format.
    please let me know.
    i tried the FM BANK_API_PP_UT_CHAR16_TO_RAW16 but no use.
    Regards,
    Rahul Wagh

    HI Vikranth,
    i tried that FM also but it is not giving me correct value.
    my hex value = 16D7A4FCA7442DDA3AD93C9A726597E4
    the character value for this should come as = test1234
    but FM given by u gives me junk values.
    is there any other way for this
    Regards,
    Rahul

  • Convert number to char

    Hi,
    I need to format numbers when converting it to char.
    I need to show the number with a precision of 3, and when between -1 and 1 to show the 0.
    ex:
    0.234
    -0.234
    1.220
    not .234
    thanks in advance

    I need to show the number with a precision of 3, and when between -1 and 1 to show the 0.This ?
    SQL> with t as (
    select 0.234 n from dual union all
    select -0.234 from dual union all
    select  13.22 from dual union all
    select 1.220 from dual
    select n, to_char(n, '990.000')  n2 from t
             N N2     
          ,234    0.234
        -0,234   -0.234
         13,22   13.220
          1,22    1.220
    4 rows selected.

  • Converting quantity to char

    How to convert quantity to char without using FM's like C14W_CHAR_NUMBER_CONVERSION,
    C14W_NUMBER_CHAR_CONVERSION,
    CHAR_INT_CONVERSION as these FM's do not exist in my server?

    Hi...
    this is my program...try this code....
    Parameters:
      p_Number(9) type c.                  " Input string.
    data:
      w_number(9) type c,                  " Input number
      w_strlen(9) type c,                  " Strlen
      w_numc(9)   type n,                  " Digit string
      w_2bit(2)   type c.                  " first 2 positions
      w_number = p_number.
      w_numc = p_number.
      write: 'The given number in words:  '.
      do 5 times.
        case sy-index.
          when 1.
            w_2bit = w_numc+0(2).
          when 2.
            w_2bit = w_numc+2(2).
          when 3.
            w_2bit = w_numc+4(2).
          when 4.
            w_2bit+0(1) = 0.
            w_2bit1(1) = w_numc6(1).
          when 5.
            w_2bit = w_numc+7(2).
        endcase.                           " CASE SY-INDEX.
       if w_2bit+0(2) ne 0.
         if w_2bit le 19.
           case w_2bit.
            when '01'.
              write 'ONE'.
            when '02'.
               write 'TWO'.
            when '03'.
               write 'THREE'.
            when '04'.
               write 'FOUR'.
            when '05'.
               write 'FIVE'.
            when '06'.
               write 'SIX'.
            when '07'.
               write 'SEVEN'.
            when '08'.
               write 'EIGHT'.
            when '09'.
               write 'NINE'.
            when '10'.
               write 'TEN'.
            when '11'.
               write 'LEVEN'.
            when '12'.
               write 'TWELVE'.
            when '13'.
               write 'THIRTEEN'.
            when '14'.
               write 'FOURTEEN'.
            when '15'.
               write 'FIFTEEN'.
            when '16'.
               write 'SIXTEEN'.
            when '17'.
               write 'SEVENTEEN'.
            when '18'.
               write 'EIGHTEEN'.
            when '19'.
               write 'NINETEEN'.
           endcase.                        " CASE 2BITS POSITIONS 1,2.
        else.
          case w_2bit+0(1).
            when '2'.
               write 'TWENTY'.
            when '3'.
               write 'THIRTY'.
            when '4'.
               write 'FOURTY'.
            when '5'.
               write 'FIFTY'.
            when '6'.
               write 'SIXTY'.
            when '7'.
               write 'SEVENTY'.
            when '8'.
                write 'EIGHTY'.
            when '9'.
               write 'NINETY'.
          endcase.                         " CASE W_2BIT+0(1)
        if w_2bit+1(1) ne 0.
           case w_2bit+1(1).
             when '1'.
                write 'ONE'.
             when '2'.
                write 'TWO'.
             when '3'.
                write 'THREE'.
             when '4'.
                write 'FOUR'.
             when '5'.
                write 'FIVE'.
             when '6'.
                write 'SIX'.
             when '7'.
                write 'SEVEN'.
             when '8'.
                write 'EIGHT'.
             when '9'.
                write 'NINE'.
             when others.
                write ' '.
            endcase.                       " CASE W_2BIT+1(1)
         endif.                            " IF W_2BIT+1(1)
      endif.                               " IF 2BIT LE 19
      case sy-index.
          when 1.
            write 'CRORES'.
          when 2.
            write 'LAKHS'.
          when 3.
            write 'THOUSANDS'.
          when 4.
            write 'HUNDREDS'.
       endcase.                            " CASE SY-INDEX
    endif.                                " IF 2BIT NE 0

  • Convert 14000 wide char table to 255 wide char table

    How to convert 14000 wide char table to 255 wide char table.
    I have used QCE1_CONVERT which is throwing exception - convert not possible.
    Please suggest.
    Thanks a lot.

    You haven't provided that much info but I guess you are looking for something like FM RSDG_WORD_WRAP does, correct?

  • URG: Converting encoded greek char from HTML page to greek char

    String geekvalues = "&# 966;&# 948;&# 945;&# 963;&# 966;&# 945;&# 963;&# 948;&# 966;";
    ( i have inserted space b/w &# ddd; because while framing the query they get converted to
    greek char)
    I parse the following string and insert the integer values in the following
    o/p stream with UTF8 ecoding.
    I can see proper greek char in the file, but when i read the contents of the file
    and try inserting these values to the DB, they appear as ���������(not what i see on my m/c) some junk char.
    bufferWriter = new BufferedWriter
    (new OutputStreamWriter(new FileOutputStream("d:\\tempAA.txt",false),"UTF8"));
    bufferWriter.write(x);
    bufferReader = new BufferedReader
    (new InputStreamReader(new FileInputStream("d:\\tempAA.txt"),"UTF8"));
    retGreekValue =bufferReader.readLine();
    String sqlStr = "INSERT INTO test_table VALUES('"+retGreekValue+"')";
    Could anybody suggest how do i insert proper greek characters in Database from the encoded string from browser.
    Thanks in advance,

    You could try the Internationalization forum. Although the question "I need to get data in script X from my database through the Internet to a browser and back, and it doesn't work" is asked frequently there, and never seems to get an answer.

  • Help! java novice, i need to convert boolean to char

    I have multiple checkboxes. Depending on what checkbox is selected, I need to convert that true boolean data to char data like 'L' or 'B'.
    If anyone can, please help. I would greatly appreciate it. Thanks.

    I'm not quite sure what you mean - boolean has only 2 states, true and false. A char can be any character. How about:
    if (someBooleanVar == true){
    someCharVar = "L";
    }else{
    someCharVar = "B";
    Again, I don't understand what you're doing, but it seems that you need to test the values of the checkboxes, and based on the values, you need to assign values to some char variables. Don't waste you're time trying to converts booleans to chars - it ain't gonna happen.

  • Converting jstring to const char * using JNI

    Hi Folks,
    Almost complete with the registry access dll and passing to java. My last question is how do I convert a jstring in a const char * ? There may be a method of the JNIEnv that I can use. Can anyone assist? Thanks.

    Look at the JNI GetString functions.

Maybe you are looking for

  • Create a link from database

    I am using dreamweaver and am new to php. I have a field Map_String containing http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype= mobile&markers=40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718

  • Adding a external display

    Is it possible to hook up a external monitor and close the powerbook and just use the external monitor? Thanks

  • Transferring a pdf file from my Mac to my iPad

    I ws told that there is A WAY OF TRANSFERRING A PDF DOCUMENT FROM MY MAC TO MY IPAD. DFoes anyone know how to do this?

  • Stretching Panel Splitters

    Hi, I have a template in which I have placed many facet references. I use this template as the base for all my pages. I have the layout set up in which I have a facet ref for a left side navigator, a top menu area, and a place for the individual cont

  • Magnetic Lasso Tool Crashing Photoshop 5 (12.0.4 x64)

    Hi there, I am experiencing this frustrating crash whenever I attempt to use this tool, and I'd realy like to be able to use it!... Initially it happened on the last graphics machine which was a HP Z800 workstation - Xeon Quad 2.8GHz, 8GB RAM, Win7Ul