0
votes

Can you please tell me what's the wrong this code and Any ideas on how to fix?

JNIEXPORT jstring JNICALL Java_COM_DEMO_TEST_SEND (JNIEnv
*env, jclass c, jstring param){
    const char* strParam = env->GetStringUTFChars(param, 0);
    UString data = s2ws(string(strParam));
    UString result = TEST::SEND(data);
    return env->NewStringUTF(ws2s(result).c_str());
}

i got following error.

error: conversion from ‘std::wstring {aka std::basic_string<wchar_t>}’ to non-scalar type ‘UString {aka std::basic_string<char>}’ requested
  UString data = s2ws(string(strParam));
1
#ifdef WIN32 typedef std::wstring UString; #else typedef std::string UString; #endif - mnts26
Then you compile your code without WIN32 set, check your project settings. - πάντα ῥεῖ
i compile it on Linux and like this g++ -Wall -g -c -I /usr/lib/jvm/java-8-oracle/include -I /usr/lib/jvm/java-8-oracle/include/linux BridgePosAPI.cpp -o BridgePosAPI.o -std=c++11 - mnts26
if its in linux what should be Ustring? - mnts26
Are you cross compiling for a windows target? Otherwise I'd leave out the windows specific stuff. - πάντα ῥεῖ

1 Answers

4
votes

The error is pretty good, actually; you're trying to use a std::string but you have a std::wstring, and the compiler doesn't know how to convert one into the other.

The fact that they're both specializations of std::basic_string does not mean that they are interchangeable.