HP (Hewlett-Packard) 5992-1918 Manual Do Utilizador

Página de 78
    System.out.println("Call dumpCore to convert " + ci + 
          " to a binary string!");
    System.out.println("The binary String: " + StackTrace.dumpCore(ci));
   }    // end methodMakeCall
//**************************************************       
  public static void main(String args[]) {
    int convertInt;
    System.out.println();
    if(args.length == 1) {
      convertInt = Integer.parseInt(args[0]);
    }
    else {
      convertInt = 757;
    }
    System.out.println("Calling method1()");
    StackTrace.method1(convertInt);
    System.out.println("Back in main, all done!"); 
  }    // end main
}      // end StackTrace
4.1.3 stacktrace.c
// File stacktrace.c 
#include "StackTrace.h" 
#include <stdio.h>
JNIEXPORT jstring JNICALL
  Java_StackTrace_dumpCore(JNIEnv *env, jclass class, jint intarg) {
  jclass     classid;
  jmethodID  methodid;
  printf("In dumpCore\n");
// Problem code.  The Class:  java.lang.IntegerX does not exist, 
// but the exception is cleared and the program continues.  
// Ultimately, failing and dumping core when getting the methodid.
// To fix, comment out the following 2 lines.
// /*
  classid = (*env)->FindClass(env, "java/lang/IntegerX");
  (*env)->ExceptionClear(env);
// */
// Working code.  The Class:  java.lang.Integer exists.  The lines
// following the FindClass manage printing out of a stack trace,
// clearing an exception, and returning to the java main when 
// FindClass fails.  
//
// Uncomment the following 6 lines and rebuild to see the program work!
 /*
  classid = (*env)->FindClass(env, "java/lang/Integer");
  (*env)->ExceptionDescribe(env);
  (*env)->ExceptionClear(env);
  if(classid == NULL) {
    return (*env)->NewStringUTF(env, "JNI FindClass failed!");
  }
 */
  methodid = (*env)->GetStaticMethodID(env, classid, "toBinaryString",
4.1 Sample Java Application
63