在android 里使用JNI,总是报错
packages/apps/SystemMointor/jni/proc_reader.c:78: error: request for member 'GetStringUTFChars' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:92: error: request for member 'FindClass' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:94: error: request for member 'NewObjectArray' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:96: error: request for member 'FindClass' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:98: error: request for member 'GetFieldID' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:99: error: request for member 'GetFieldID' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:108: error: request for member 'SetObjectField' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:108: error: request for member 'NewStringUTF' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:116: error: request for member 'SetObjectField' in something not a structure or union
packages/apps/SystemMointor/jni/proc_reader.c:118: error: request for member 'SetObjectArray' in something not a structure or union
我已经include了jni.h

解决方案 »

  1.   

    帖出代码来看看,另外尝试一下,包含的jni.h可不可找开,看看系统能不能找到jni所在路径 
      

  2.   

    问题解决了,原来是这样的:
    如果是c程序,要用 (*env)->
    如果是C++要用 env->ps:在linux下如果.c文件中用 “env->” 编译会找不到此结构,必须用“(*env)->”,或者改成.cpp文件,以 c++的方式来编译。以下是两者的区别:jni.h中struct JNINativeInterface_;struct JNIEnv_;#ifdef __cplusplus
    typedef JNIEnv_ JNIEnv;
    #else
    typedef const struct JNINativeInterface_ *JNIEnv;
    #endif/*
    * We use inlined functions for C++ so that programmers can write:
    *
    *   env->FindClass("java/lang/String")
    *
    * in C++ rather than:
    *
    *    (*env)->FindClass(env, "java/lang/String")
    *
    * in C.
    */即C++中使用
    env->FindClass("java/lang/String")
    C中使用(*env)->FindClass(env, "java/lang/String")
      

  3.   

    4楼 你再定义一个指针,用它去访问成员 
    如你*(p)->next报错 你定义一个q   q=*p; q->next;
      

  4.   

    我在用gcc编译时也遇到类似的问题,不过我用(*env)->时也会报错,用(*env).时才通过。
      

  5.   

    我跟楼主一样,改了就好了。
    PS 我用的是Cygwin编译。
      

  6.   

    我也是在linux下,用gcc编译的.c文件。以上各种方法(*env)->   (*env).我都试过了,还是报错。以下是我的代码:
    int center_molecule(molecule *m) 

      int i,j;
      double xcen,ycen,zcen;
      xcen=ycen=zcen=0;
      for (i=0;i<3;i++){
         for (j=0;j<4;j++){
             if (m.RESIDUE[i].ATOM[j].selected){
                xcen+=m.RESIDUE[i].ATOM[j].x;
                ycen+=m.RESIDUE[i].ATOM[j].y;
                zcen+=m.RESIDUE[i].ATOM[j].z;
               //natoms++;
             }
         }
      }  xcen/=12;
      ycen/=12;
      zcen/=12;
      for (i=0;i<3;i++){
         for(j=0;j<4;j++)
         {
          m.RESIDUE[i].ATOM[j].x-=xcen;
          m.RESIDUE[i].ATOM[j].y-=ycen;
          m.RESIDUE[i].ATOM[j].z-=zcen;
         }
      }
      return(0);
    }
    请求指教!!!!