Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4095427

GetMethodID() failed to work on (V)I, etc

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.1.3
    • hotspot
    • x86
    • windows_95



      Name: rm29839 Date: 11/25/97


      Simply use the HelloWorld example of JNI. Modify
      the HelloWorld class and HelloWorldImp.c a little.

      Here is the java class:

      class HelloWorld {
         protected int number;
         protected double value;

         public HelloWorld()
         {
             number = 1;
             value = 30.0;
         }

         public int getNumberV()
         {
             return number;
         }

         public int getNumbetI(int i)
         {
             return number;
         }

         public double getValueV()
         {
             return value;
         }

         public double getValueI(int i)
         {
             return value;
         }

         public native void displayHelloWorld();

         static {
            System.loadLibrary("hello");
         }
      }

      This is the native code:

      #include <jni.h>
      #include "HelloWorld.h"
      #include <stdio.h>

      JNIEXPORT void JNICALL
      Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
      {
         jclass cls = (*env)->GetObjectClass(env, obj);
         jmethodID mid;

         mid = (*env)->GetMethodID(env, cls, "getNumberV", "(V)I");
         if(mid == 0)
            printf("GetMethodID(...,\"(V)I\") failed.\n");
         mid = (*env)->GetMethodID(env, cls, "getNumberI", "(I)I");
         if(mid == 0)
            printf("GetMethodID\(...,\"(I)I\") failed.\n");
         mid = (*env)->GetMethodID(env, cls, "getValueV", "(V)D");
         if(mid == 0)
            printf("GetMethodID\(...,\"(V)D\") failed.\n");
         mid = (*env)->GetMethodID(env, cls, "getValueI", "(I)D");
         if(mid == 0)
            printf("GetMethodID\(...,\"(I)D\") failed.\n");
         printf("Hello world!\n");
         return;
      }

      This is the run-time result:

      GetMethodID(...,"(V)I") failed.
      GetMethodID(...,"(I)I") failed.
      GetMethodID(...,"(V)D") failed.
      Hello world!
      (Review ID: 20708)
      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: