Thread: jni C++

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

    jni C++

    so hi basically really confused and new to jni. um basically i have in C

    jstring str;
    char * str1 = getStringhere(); // this just returns a char* of a string in a another // function i created
    str = str1;

    and this works but once i changed it to c++ it says almost the exact same thing
    i get an error like cannot convert char* to _jstring*

    it worked for C y not c++

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the exact error message?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, the languages use somewhat different interfaces, it seems.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    iono basically that cannot convert char* to *jstring

    do u think if i just have a .cpp program but extern everything into C that the program could compile

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by kiros88 View Post
    iono basically that cannot convert char* to *jstring

    do u think if i just have a .cpp program but extern everything into C that the program could compile
    Yes, and use the C include file only, of course.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Does anyone know a basic code sample of a .cpp being called by java i just want to see an example cuz this is frustrating ive tried extern it and its still not working its complaing bout some of the sytax in my jni funciton but in the end i need a cpp file have the jni native function call so i could easily skip the C stuff if there was an example online or out there that uses .cpp in a simple version that does helloworld

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by kiros88 View Post
    Does anyone know a basic code sample of a .cpp being called by java i just want to see an example cuz this is frustrating ive tried extern it and its still not working its complaing bout some of the sytax in my jni funciton but in the end i need a cpp file have the jni native function call so i could easily skip the C stuff if there was an example online or out there that uses .cpp in a simple version that does helloworld
    Oh, pity you. Nobody said that programming would be easy, tho! I hate to ask, but did you even RTFM...?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of strings in JNI
    By kiros88 in forum C Programming
    Replies: 2
    Last Post: 07-21-2010, 12:40 PM
  2. Timers
    By Deb in forum C Programming
    Replies: 16
    Last Post: 04-23-2007, 10:15 AM
  3. JNI
    By GoLuM83 in forum C Programming
    Replies: 0
    Last Post: 01-03-2007, 10:53 AM
  4. stdout with JNI
    By GoLuM83 in forum C Programming
    Replies: 4
    Last Post: 12-14-2006, 01:27 PM
  5. Does anybody know how can we use Java to prepare a C HeaderFile
    By arvindkr_1999 in forum C++ Programming
    Replies: 8
    Last Post: 04-28-2004, 03:16 AM