public class CplusGraphics {
            static{
                    System.out.println("方法被调用之前--------------");
                    System.loadLibrary("ShapeRead");
                    System.out.println("方法被调用--------------");
            }
            public static native int GetShpType();       
    }    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class com_graphics_base_CplusGraphics */    #ifndef _Included_com_graphics_base_CplusGraphics
    #define _Included_com_graphics_base_CplusGraphics
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class:     com_graphics_base_CplusGraphics
    * Method:    GetShpType
    * Signature: ()I
    */
    JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpType
      (JNIEnv *, jobject);    #ifdef __cplusplus
    }
    #endif
    #endif
    #include "com_graphics_base_CplusGraphics.h"
    #include <stdlib.h>    #ifndef _Included_com_fileText_fileRead
    #define _Included_com_fileText_fileRead
    #ifdef __cplusplus    extern "C" {
    #endif
    //jobject arraylist;    JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpType
      (JNIEnv *env, jobject obj)    /*
    * Class:     CplusGraphics
    * Method:    SetShpType
    * Signature: (I)V
    */
    {
            int i = 100;
            jint type = i;
            return type;
    }    #ifdef __cplusplus
    }
    #endif
    #endif    //其他类里面调用
    System.out.println(CplusGraphics.GetShpType());
然后编译没问题,android模拟器里面运行程序,屏幕会卡住。

System.out.println("方法被调用之前--------------");
                System.loadLibrary("ShapeRead");
                System.out.println("方法被调用--------------");
中只有第一句输出了。就卡在第二句java语句上了。  求各位大大帮忙看看哪里错了。

解决方案 »

  1.   

    你的SO文件有没整到你的APK里面去?
      

  2.   

    so文件都没加载成功,so文件要拷到libs\armeabi\下。可以检查下/data/data/包/lib下有没so文件生成。
      

  3.   

    应该是没找到库文件,自己做的jni接口还是编进应用程序的好
      

  4.   

    谢谢楼上各位,问题解决了。 上面少贴了两行,是声明了一个类的对象,就是这部分出错了。这个类中其中使用了fstream,引用的是#include<fstream>,把头文件换成#include <iostream>之后问题解决了。感觉很莫名   
    是ndk的问题?不知道各位大大使用jni的时候是如何调试c/c++代码的?能否java代码转到c++代码?