你用的不是静态方法,看看你的java代码

解决方案 »

  1.   

    你是说调用topsideTesttools方法的方法应该是静态方法?
      

  2.   

    加了static修饰符,还是一样的错误啊
      

  3.   

    //Jrunc.java
    package jnijc;public class Jrunc
    {
      public Jrunc()
      {
      }
      public native static String helloWorld();
      public native static int sum(int a,int b);}
    //Test.java
    package jnijc;public class Test
    {
      public Test()
      {
      }  public static void main(String[] args)
      {
        Test test1 = new Test();
        try
        {
          System.loadLibrary("jnijc_Jrunc") ;
          Jrunc jc=new Jrunc();
          System.out .println(jc.helloWorld() ) ;
          System.out .println(jc.sum(1,2) );
        }
        catch(Exception ex)
        {
          ex.printStackTrace() ;
        }
      }}
    //jnijc_Jrunc.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class jnijc_Jrunc */#ifndef _Included_jnijc_Jrunc
    #define _Included_jnijc_Jrunc
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     jnijc_Jrunc
     * Method:    helloWorld
     * Signature: ()Ljava/lang/String;
     */
    JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld
      (JNIEnv *, jclass);/*
     * Class:     jnijc_Jrunc
     * Method:    sum
     * Signature: (II)I
     */
    JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum
      (JNIEnv *, jclass, jint, jint);#ifdef __cplusplus
    }
    #endif
    #endif
    //jnijc_Jrunc.cpp
    #include "jnijc_Jrunc.h"
    /*
     * Class:     jnijc_Jrunc
     * Method:    helloWorld
     * Signature: ()Ljava/lang/String;
     */
    JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld
      (JNIEnv *env, jclass jc)
    {
    char hello[]="hello world!";
    jstring a=env->NewStringUTF(hello);
    return a;
    }/*
     * Class:     jnijc_Jrunc
     * Method:    sum
     * Signature: (II)I
     */
    JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum
      (JNIEnv *env, jclass jc, jint jia, jint jib)
    {
    jint sum=jia+jib;
    return sum;
    }
    int main()
    {
    return 0;
    }
      

  4.   

    你的意思是native方法必须是静态的?但是java tutorial里面不是啊
    另外,只能在main方法里调用吗?其它方法不行?
      

  5.   

    我改为下面这样可还是一样的错误啊
    public native static void topsideTesttools();
    ...
    public static void callback() throws Exception{
    System.loadLibrary("topside");
    new TestToolsBootstrap().topsideTesttools();
    ...
    }
      

  6.   

    已经搞定了,native方法不需要是静态的,问题出在我的java程序是在包里的,在c程序中函数名里面没有包含包。