HelloJni.javapublic class HelloJni extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);        /* Create a TextView and set its content.
         * the text is retrieved by calling a native
         * function.
         */
        TextView  tv = new TextView(this);
        tv.setText( stringFromJNI() );
        setContentView(tv);
    }    public native String  stringFromJNI();
    static {
        System.loadLibrary("hello-jni");
    }
}hello-jni.ccextern "C"jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    std::string s = "Hello from JNI !";
    try
    {
        if (::getenv("NON_EXISTENT_ENVIRONMENT_VARIABLE") == NULL)
            throw std::runtime_error("Hello from JNI for full C++ support看看");
    }
    catch (std::exception &ex)
    {
        s = ex.what();
        std::cout << "Exception catched: " << ex.what() << std::endl;
    }
    return env->NewStringUTF(s.c_str());
}
如果把“看看”两个中文字去掉就能在模拟器中正常显示出来,不然,模拟器输出屏幕只是闪一下就没了。
帮帮忙,谁能把正确的代码贴一下。

解决方案 »

  1.   

    你想显示那两个“看看”吗?还是"Hello from JNI !"?
      

  2.   

    现在的问题是        看看
    不想显示Hello from JNI !
    其实再简单点
    hello-jni.ccextern "C"jstring
    Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
      jobject thiz )
    {
         std::string s = "Hello from JNI !看看";
        return env->NewStringUTF(s.c_str());
    }
      

  3.   

    输出日志:
    ======cut here======================
    JNI WARNING: illegal continuation byte 0xd0
    string: "Hello form JNI with full C++ support !~\(≧▽≦)/(乱码)"
    in Lcom/example/hellojni/HelloJni; stringFromJNI() Ljava/lang/String; (NewStringUTF)
    ======cut here======================
    因为这个警告就挂掉了,所以模拟器屏幕闪一下就没了
      

  4.   

    hello-jni.ccextern "C"jstring
    Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
      jobject thiz )
    {
      std::string s = "Hello from JNI !看看";
      return env->NewStringUTF(s.c_str());
    }
      

  5.   

    JNI不支持中文吧!因为没有字库!