JNI help - FindClass

I have recently been trying to play around with JNI, but every time I run my program it says that it cannot locate my file (aka I get the error that it couldn't find the CTF class). I'm currently using xcode on my mac. Here is my code:
* ctf.c
* CTF
#include "JavaVM.framework/Headers/jni.h"
int main() {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
jclass cls;
jmethodID cid, mid;
jstring opp_str, opp_str_loc;
jobjectArray args;
jobject class_instance, return_val;
char classpath[4096] = "-Djava.class.path=.:";
/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = JNI_VERSION_1_4;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
//this is the directory where my CTF.class file is located
char *classpathOption = strcat(classpath, "~/Documents/Research/CTF");
fprintf(stdout, "class path is %s\n", classpathOption);
JavaVMOption options[1];
options[0].optionString = classpathOption;
vm_args.version = 0x00010004;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
} else {
printf("created Java VM just fine.\n");
cls = (*env)->FindClass(env, "CTF");
if (cls == 0) {
fprintf(stderr, "Can't find CTF class\n");
exit(1);
cid = (*env)->GetMethodID(env, cls, "<init>", "()V");
if (cid == 0) {
fprintf(stderr, "Can't find CTF constructor\n");
class_instance = (*env)->NewObject(env, cls, cid);
if (class_instance == 0) {
fprintf(stderr, "Can't create CTF class\n");
mid = (*env)->GetMethodID(env, cls, "makePrediction", "([Ljava/lang/String;)V");
if (mid == 0) {
fprintf(stderr, "Can't find CTF.makePrediction\n");
exit(1);
opp_str = (*env)->NewStringUTF(env, "opponent");
if (opp_str == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
opp_str_loc = (*env)->NewStringUTF(env, "desk");
if (opp_str_loc == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
args = (*env)->NewObjectArray(env, 2,
(*env)->FindClass(env, "java/lang/String"), opp_str);
if (args == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
} else {
(*env)->SetObjectArrayElement(env, args, 1, opp_str_loc);
return_val = (*env)->CallObjectMethod(env, class_instance, mid, args);
(*jvm)->DestroyJavaVM(jvm);
return 0;

I'm using java 1.4.2, and jni version 1.4.
Here's the c code:
#include "wwhd.h"
#include "JavaVM.framework/Headers/jni.h"
#include <stdlib.h>
char *wwhd(char** knowledge) {
    JNIEnv *env;
    JavaVM *jvm;
    JavaVMInitArgs vm_args;
     jint res;
    jclass cls;
    jmethodID cid, mid;
    jstring opp_str, opp_str_loc, method_str;
    jobjectArray args;
     jobject class_instance, return_val;
    char classpath[4096] = "-Djava.class.path=.:";
    //JNI_GetDefaultJavaVMInitArgs(&vm_args);
     char *classpathOption = strcat(classpath, getenv("CLASSPATH"));
     classpathOption = strcat(classpathOption, ":");
     classpathOption = strcat(classpathOption, "~/Documents/Research/NRL/Eclipse_Workspace/CTF");
     JavaVMOption options[1];
     options[0].optionString = classpathOption;
     vm_args.version = 0x00010004;
     vm_args.options = options;
     vm_args.nOptions = 1;
     vm_args.ignoreUnrecognized = JNI_FALSE;
         /* Create the Java VM */
        res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
        if (res < 0) {
            fprintf(stderr, "Can't create Java VM\n");
            exit(1);
        } else {
          printf("created Java VM just fine.\n");
        cls = (*env)->FindClass(env, "CTF_Human");
        if (cls == 0) {
            fprintf(stderr, "Can't find CTF_Human class\n");
           (*jvm)->DestroyJavaVM(jvm);
            exit(1);
        } else {
          fprintf(stdout, "Found CTF_Human class\n");
     cid = (*env)->GetMethodID(env, cls, "<init>", "()V");
     if (cid == 0) {
          fprintf(stderr, "Can't find CTF_Human constructor\n");
          (*jvm)->DestroyJavaVM(jvm);
     } else {
          fprintf(stdout, "Found CTF_Human constructor successfully\n");
     class_instance = (*env)->NewObject(env, cls, cid);
         if (class_instance == 0) {
          fprintf(stderr, "Can't create CTF_Human class\n");
          (*jvm)->DestroyJavaVM(jvm);
     } else {
          fprintf(stdout, "Created CTF_Human class w/out a problem\n");
     cls = (*env)->GetObjectClass(env, cls);
     if (cls == 0) {
         fprintf(stderr, "Can't get CTF_Human class from instance\n");
          (*jvm)->DestroyJavaVM(jvm);
                  exit(1);
          } else {
          fprintf(stdout, "Got CTF_Human class from instance\n");
     mid = (*env)->GetStaticMethodID(env, cls, "main", "([java/lang/String;)V");
         if (mid == 0) {
                  fprintf(stderr, "Can't find CTF_Human.main\n");
          if ((*env)->ExceptionOccurred(env)) {
               fprintf(stderr, "about to exception describe\n");
               (*env)->ExceptionDescribe(env);
               fprintf(stderr, "done exception describing\n");
          (*jvm)->DestroyJavaVM(jvm);
                 exit(1);
    (*jvm)->DestroyJavaVM(jvm);
     return "";          
}and the output is
Running...
created Java VM just fine.
Found CTF_Human class
Found CTF_Human constructor successfully
Created CTF_Human class w/out a problem
Got CTF_Human class from instance
Can't find CTF_Human.main
about to exception describe
java.lang.NoSuchMethodError: main
Exception in thread "main" done exception describing
Debugger stopped.
Program exited with status value:1.(gdb)
The java code (main function) is:
     public static void main(String[] args) {
          String[] arg = new String[2];
          arg[0] = "opponent";
          arg[1] = "desk";
          CTF h =  new CTF();
          System.out.println(h.makePrediction(arg, true, null));  //another fn in the class
          System.exit(0);
     }Thanks for all your help/time...

Similar Messages

  • JNI problems (findclass and vm error)

    Hi,
    First please apologize if this question has already been asked. I've looked at the archives and I haven't found any answer to these problems. Thanks to take the time to read this quite long post, but I've tried to be sufficiently explicit...
    So, here's what I want to do: in the native code, generate a list (ArrayList) with some integers in it. I must add that I'm not a Java expert.
    Here's the java code calling the native function:
    package be.ac.umrtc;
    public class Main {
         public native List computeRoute(int src, int dst, float reservation)
         static{
              System.loadlibrary("cspf");
         public static void main(String[] args) throws Exception{
         List path = new Main().computeRoute(lsp.getFrom(),lsp.getTo(),lsp.getReservation());
    Now the native code:
    #include <jni.h>
    #include "be_ac_umrtc_Main.h"
    JNIEXPORT void JNICALL Java_be_ac_umrtc_Main_computeRoute(JNIEnv *env, jobject obj, jint src, jint dst, jfloat reservation){
         arraylistClass = (*env)->FindClass(env,"/java/util/ArrayList");
         if (arraylistClass == NULL){
              return NULL; // exception thrown
         cid = (*env)->GetMethodID(env,arraylistClass,"<init>","()V");
         if (cid == NULL){
              return NULL; // exception thrown
         arraylist = (*env)->NewObject(env, arraylistClass, cid);
         tempClass = (*env)->GetObjectClass(env,arraylist);
         jmethodID mid = (*env)->GetMethodID(env,tempClass,"add","(Ljava/lang/Object;)Z");
         while (longListPopBack(&computedroute,&value2)!=-1){
              fprintf(stderr,"Valeur de value: %d\n", value2);
              if (mid==0){
                   return;
              fprintf(stderr,"%d\n", bool = (*env)->CallBooleanMethod(env, arraylist, mid, value2));
    (*env)->DeleteLocalRef(env, arraylistClass);
    return arrayList;
    I get a NoClassDefFoundError on java/lang/ArrayList.
    So, I've tried to pass a List object "path" as argument to the native method (created in java)
    and proceed with:
    arraylistClass = (*env)->GetObjectClass(env,path);
    instead of FindClass.
    It seems to work well, the first call to callBoleanMethod returns 1. But then, the next call in the loop ends in a VM ERROR:
    HotSpot Internal Error, VM Error
    # HotSpot Virtual Machine Error, Internal Error
    # Please report this error at
    # http://java.sun.com/cgi-bin/bugreport.cgi
    # Java VM: Java HotSpot(TM) Client VM (1.4.2_03-b02 mixed mode)
    # Error ID: 43113F32554E54494D45110E4350500308
    # Problematic Thread: prio=1 tid=0x08052c30 nid=0x346d runnable
    Heap at VM Abort:
    Heap
    def new generation total 576K, used 0K [0x44df0000, 0x44e90000, 0x452d0000)
    eden space 512K, 0% used [0x44df0000, 0x44df02a8, 0x44e70000)
    from space 64K, 0% used [0x44e80000, 0x44e80000, 0x44e90000)
    to space 64K, 0% used [0x44e70000, 0x44e70000, 0x44e80000)
    tenured generation total 3724K, used 2233K [0x452d0000, 0x45673000, 0x48df0000)
    the space 3724K, 59% used [0x452d0000, 0x454fe540, 0x454fe600, 0x45673000)
    compacting perm gen total 4096K, used 3166K [0x48df0000, 0x491f0000, 0x4cdf0000)
    the space 4096K, 77% used [0x48df0000, 0x49107890, 0x49107a00, 0x491f0000)
    Java Result: 129
    The questions are thus:
    1. why does FindClass not work?
    2. why does the second call to callboleanmethod fails?
    Thanks a lot for your help.
    Olivier

    Thanks, so now I just want to return an array of integers.
    int[] computeRoute(...); in JAVA
    JNIEXPORT jintArray JNICALL Java_be_ac_umrtc_Main_computeRoute(JNIEnv *env, jobject obj, jint src, jint dst, jfloat reservation){
    int intarray[size];
    return intarray;
    does not work
    I've tried casting : return (jintArray) intarray;
    but no success
    How can I create a jintArray? And then how to insert elements in this jintArray? I've seen in the books and the tutorial how to get element from such a jintArray passed as argument... but how to create it (how to fix size when creating it) and how to set elements is not evident to me.
    Thanks for your patience.

  • Need urgent (JNI) help

    I tried this question in the JNI forum also, but there are not many ppl there, and I'm terribly stuck at the moment.
    Hi,
    I'm new with java and new with JNI.
    I'm trying to make an interface between java and a c__ program.
    I get everything wroking except for one method. And I have no clue how to solve it. I have been reading for two days on the net now, and All the things I encounter are too complicated too understand for me at this stage.
    I have a function in c++ :
    // get pair at internal iterator
            inline bool             get(classifType&        theID, string&  theName)
    const
            { return (Converter::get(theID, theName));      }Basicly it will give me back a (Map) key value pair (as reference argument) and a boolean if succeeded.
    in the java file it stands as:
    public  native String  get(long jarg1,String jarg2)the problem is that I have no idea how to work with reference arguments.
    Another approach would also be possible, It would also be good to have a java method:
    public  native Map     getTypes();That would give me a Map with all the available key value pairs.
    The c++ code to get them all would be:
                   ParamTypeConv   ptc(&conn);
                    LOG_INFO ("Walking through the list:");
                    ptc.top();
                    do {
                            string  strvalue;
                            int16   value;
                            if (ptc.get(value, strvalue)) {
                                    LOG_INFO_STR (value << " : " << strvalue);
                    } while (ptc.next());I was thinking in this direction:
    JNIEXPORT jobject JNICALL Java_nl_astron_lofar_sas_otb_jotdb2_jClassifConv_getT\
    ypes(JNIEnv *env, jobject) {
      // Construct java Map
      jobject itemMap, jkey,jval,jold,result;
      jclass mapClass;
      jmethodID init,put;
      mapClass = env->FindClass("java/util/Map");
      init = env->GetMethodID(mapClass, "<init>", "()V");
      result = env->NewObject(mapClass, init);
      put = env->GetMethodID(mapClass, "put",
                 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
      classifConv->top();
      do {
        string  value;
        long    key;
        if (classifConv->get((classifType)key, value)) {
         jkey   = key;             <<<<<< WRONG
         jvalue = value;        <<<<<<WRONG
          jold   = env->CallObjectMethod(env, result, put, jkey, jval);
      } while (classifConv->next());
      return result;
    But that goes wrong also, no idea how to make object of that (if that is what is going wrong)
    Could anybody please help me out on this ?
    Either solution would be good for me, but pure for extending my knowledge It would be great if someone could shed some light on the first approach also please.
    Thanks for your time and knowledge sharing

    Allready working on it in the Native Methods tread

  • Problems creating a Java Array using JNI-HELP!

    Hi,
    I am trying to create a Java Array using JNI.I have posted the code below. The problem is that the oth element is added correctly to the Array but when the JVM gets to the next element...it goes for a toss. It is not able to create a new instance of the object in GetUGEntity() function...there seems to be some problem in creating a new instance of the object!
    Can somebody help me with this?
    jobject GetUGEntity(JNIEnv *env, UF_DISP_j3d_entity_t* entity_list)
         int numVerts=0, numStrips=0;
         jfieldID fid;
         jdoubleArray jTransform=NULL;
         jstring jstrName=NULL;
         jdoubleArray jNormals=NULL;
         //Init an Entity object
         cout<< "**Getting New Class Reference...";
         jclass jEntity = env->FindClass("Lcom/wipro/java3d/rmi/Entity;");
         cout << "**got Class reference..."<<endl;
         if (jEntity == NULL)
              return NULL;
         cout<<"Creating new object instance...";
         jmethodID mIDInit = env->GetMethodID(jEntity, "<init>", "()V");
         cout<<"Got java method id...";
         jobject javaObj = env->NewObject(jEntity, mIDInit);
         if (javaObj==NULL)
              return NULL;
         cout << "Created!" << endl;
         //Entity ID
         cout<< "**Setting eid...";
         fid=env->GetFieldID(jEntity,"eid","I");
         jint eid = (jint)(entity_list)->eid;
         env->SetIntField(javaObj, fid, eid);
         //env->DeleteLocalRef(eid);
         cout << "Done!" << endl;
         cout << "Done!" << endl;
         cout<< "**Returning jobject...";
         return javaObj;
    jobjectArray createJArray(JNIEnv* env, UF_DISP_j3d_entity_t** entity_list, int noOfEntities )
         UF_DISP_j3d_entity_t* tempVar=NULL;
         cout<<"*Creating Jobjectarray...";
         jobjectArray jEntityArray = (jobjectArray) env->NewObjectArray(noOfEntities,
              env->FindClass("Lcom/wipro/java3d/rmi/Entity;"),NULL);
         cout<<"Created!"<<endl;
         for(int i=0; i<noOfEntities;++i)
              tempVar = &(*entity_list);
              if (tempVar !=NULL)
                   cout<<"*Trying to get Entity...."<<endl;
                   jobject jEntity = GetUGEntity(env, tempVar);
                   if (jEntity!= NULL)
                        cout<<"Got Entity!" <<endl;
                        cout <<"*Setting Array Element....";
                        env->SetObjectArrayElement(jEntityArray, i, jEntity);
                        cout << "Done!" << endl;
                   else
                        printf("ERROR: Did not get Entity Reference");
              else
                   printf("ERROR: Got a NULL Reference!");
         return jEntityArray;

    Hi Deepak,
    Could you please let us know upto which line your code is going safe. Try printing the value in the structure before you send that to the method GetUGEntity().
    I am not too sure that would be a problem. But I have faced a problem like this, wherein I tried to access a structure for which I have not allocated memory and hence got exception because of that.
    Since your JNI code seems to be error free, I got doubt on your C part. Sorry.
    Dhamo.

  • Newbie needs JNI help

    the JNI tutorial speaks about creating a "shared directory" where a "dll" file is created and stored.
    How do i create this ".dll" file and store it into the shared directory ? ...

    Hi,
    Creating dll is outside the realm of Java programming. You need to use some language like C/C++/VB etc. Any good C/C++ IDE has wizards to help you create a dll. Use them. There is a free one at www.bloodshed.org called Dev-C++.
    cheers
    Projyal

  • JNI Help!

    I am trying to build a simple test program to call a win32api dll.
    Here's the code:
    import java.util.*;
    import java.lang.*;
    public class JNItest
    static
    System.loadLibrary( "winmm" );
    System.out.println( "Library loaded." );
    static native long PlaySound(String lpszSound, long dwFlags, long fuSound);
    public static void main (String args[])
    long returnCode = 0;
    long xx = 0;
    long flags = 0;
    String soundFile = "\\MEDIA\\The Microsoft Sound.wav";
    System.out.println("Playing '" + soundFile + "'...");
    returnCode = PlaySound(soundFile, xx, flags);
    The code compiles fine, with no warnings. I then run javah -jni to build the header file. This also works fine.
    When I run it, the static initializer fires and loads the native library without error. However, when I actually hit the line of code to call the PlaySound method I get the following exception: "java.lang.UnsatisfiedLinkError: PlaySound".
    My path includes a link to c:\winnt\system32 where winmm.dll resides. If you move this dll the loadLibrary method will fail, so I know it is finding the dll.
    ??? Does anyone know why the call to PlaySound is failing?
    Thanks,
    alan

    It failed because you cannot call a Win32 API function in Java without writing a wrapper dll. What you did is just creates a C/C++ header file.
    As for why the static initializer successfully loads the dll is because the file exists.
    All C/C++ codes for the native method should have something likeJNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)As for your's, the function should beJNIEXPORT jlong JNICALL Java_JNItest_PlaySound(JNIEnv *env, jobject obj, jstring lpszSound, jlong dwFlags, jlong fuSound)For more information:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html

  • JNI help please

    I am currently working with a friend on developing a java application. The application will include a media player in it. We found the JMF very complicated and unable to even render the most simple media formats so we have decided to use another cross platform media player's rendering library. To get this library to render on a control of my choice though, I have to provide it with the window ID of the control (hWnd on windows and the x11 window handle on linux). After doing a tremendous amount of research, we have concluded that the only way of obtaining the window id is to use JNI to load a native library that extracts the window id. I can't get JNI to work. When i import my native library on windows and attempt to call the function, java throws an exception:
    java.lang.UnsatisfiedLinkError: getHWND
    I can't even get a native library to compile on linux; the compiler says there are syntax errors in included file jawt.h
    Any explanation as to why im gettign these errors would be appreciated. An easier way to get the window id all from java would be greatly appreciated.
    Im using a java1.6.0 snapshot.

    You should be more specific on how your java code is actually calling native functions.
    Can you show us the appropriate java code, and also the appropriate native code of the wrapper?
    Regards

  • Problem calling a jre7 class from jni

    Hi,
    We have a class in java 7 and need to load it from a native code. The system already load some classes in java 6 with JNI, needing an upgrade. I install the new JDK, change include directories and link references in my VC project. All was well, until need to start the jre7 from jni... When call method JNI_CreateJavaVM, we pass the jni version in vm_args.version parameter, but don't have a definition for newer version than 1.6.
              JavaVMInitArgs vm_args;
              vm_args.version = JNI_VERSION_1_6;
              vm_args.nOptions = 2;
              vm_args.options = options;
              vm_args.ignoreUnrecognized = 0;
              int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    Running the program, when calls JNI method "FindClass" for a jre7 class, the jvm throws an UnsupportedClassVersionError exception. The exception is clear, I'm running a class that the jvm doesn't support, to be a newer version than it.
    The problem: How do I to start, from JNI, a JVM that supports the jre7 classes? I tryed to search, but don't found any reference for this. That's possible? The JNI library supports jre7?
    Regards
    ps. sorry for my "brazilian" english

    Yes, is the problem, now solved.
    The cause was in the User Environment Variables, that sets the path to the jre6, preceding my settings when runs the application. I had checked the System environment, but had forgotten the User environment.

  • Jni COM and MORE

    hello
    i'm french student and i try to make a program to use program in C and other language(Matlab for example) in a JAVA class.
    I would know ,if with a COM object we can permit at a java program to use any functions which are developped in other language.
    And if we can use COM object to call ,in Java class, functions wich are stockpiled inside DLL.
    I have made an experience with JNI and DLL based on c program ,but it is a very long and constraining way to realize a litle execution .
    I search an over way to developpe more easly this project.
    Sorry for my english
    if you have understand my question and if you have any document or idea on subject I'mwaiting your response
    thanks for your attention

    This is a complex issue:
    The simple answer is use JNI
    For a really good book on this topic, including COM integration, I recommend Stuart Halloway's excellent book "Component Development for the Java Platform" ISBN 9 780201 753066
    Stuart has developed a JNI helper system call JAWIN, whixh I have used to access COM objects. I have used this to insert data into Microsoft Outlook, for example.
    Hope this helps ....

  • Thanks bschauwe, but more questions on your post...

    You said in a helpful reply to my post:
    public class TestDataObject {
    public void setX(int val) {
    this.x = val;
    public int getX() {
    return this.x;
    }Your native methods take one of these objects as a parameter, or return one of these objects.
    public class Test {
    public native void setTestData(TestDataObject obj);
    public native TestDataObject getTestData();
    }The TestDataObject constructor, getter, and setter methods can all be invoked with JNI (C)
    code. In other words, to return the test data, you
    o use JNI to call the TestDataObject constructor.
    o Use JNI to call the setters to fill in the data.
    o Return the reference to the TestDataObject.
    I was curious bout the use JNI to call the TestDataObject constructor. Im not sure what u meant, I know there was a JNI call that could be done from C that was titled: Invoking a Java Method. IS that what you meant? like Native access to an objects own methods?
    If so I can check that chapter out in the book, if not then im still lost (as most this new JNI stuff is all greek to me)
    This is what i was starting to write before I realized I might be wrong in interpreting what you said:
    JNIEXPORT void JNICALL Java_AbfaRegion_setJSource
      (JNIEnv *env, jobject thisObj, jobject actualObj)
         jclass clazz = env->GetObjectClass(actualObj);
         jfieldID fid= env->GetFieldID(clazz, "height", "I");
         env->SetIntField(actualObj, fid, myValFromStruct);
    }Here i was explciting trying to set private members of the JSource class, thats not what u meant really is it?
    Thanks for any help again,
    Shane

    Let's assume you create a java class called TestDataObject. You define a constructor, a couple of getters, and a couple of setters.
    Using TestDataObject content in a JNI routine: You pass a TestDataObject to your native routine as a parameter. In the C code, you use JNI functions to invoke the (java) methods on the java object, getting back data types like jint, jlong, jstring, ....
    Using TestDataObject to pass back results from a JNI routine: In the C code, you use JNI functions to invoke the (java) methods of a TestDataObject. But wait! First you use JNI functions to create a new TestDataObject! In other words, JNI helps you invoke the constructor method.
    A C function can invoke java methods using JNI calls in roughly the following sequence:
    o Call a JNI function to get a reference to the class - a kind of "type" record. FindClass or GetObjectClass.
    o Call a JNI function to get the ID of the method you want to invoke: GetMethodID (class is a parameter)
    o Call a JNI function to invoke the method. CallxxxMethod (class and method ID are parameters to this function. If you are not calling a constructor or a static method, then instead of the class, pass an object pointer.)
    Finally: You can do what your code shows - shove data right into private data members of java classes. I choose instead to invoke getters and setters.

  • Can't find class because of try catch block ?!

    Hello,
    I'm using the JNI to use a java library from my c++ code.
    JNI can't find the "Comverse10" class below, but when i put the try catch block in createMessage in comment, FindClass succeeds ?!
    Unfortunatly i need the code inside the try block ;-)
    I tried a few things, but none of them worked:
    - let createMessage throw the exception (public void createMessage throws ElementAlreadyExistsException ), so there isn't a try catch block in createMessage => result: the same
    - make a "wrapper" class Comverse that has a Comverse10 object as attribute and just calls the corresponding Comverse10.function. Result: Comvers could be found, but not constructed (NewObject failed).
    Can someone tell me what is going on ?!
    Thank you,
    Pieter.
    //Comverse10 class
    public class Comverse10 {
    MultimediaMessage message;
    /** Creates a new instance of Comverse10 */
    public Comverse10() {
    public void createMessage() {
    TextMediaElement text1 = new TextMediaElement("Pieter");
    text1.setColor(Color.blue);
    SimpleSlide slide1 = new SimpleSlide();
    //if i put this try catch block in comment, it works ?!
    try{
    slide1.add(text1);
    catch(com.comverse.mms.mmspade.api.ElementAlreadyExistsException e){}
    MessageContent content = new MessageContent();
    content.addSlide(slide1);
    this.message = new MultimediaMessage();
    message.setContent(content);
    message.setSubject("Mijn subjectje");
    for those of you who are intersted: here's my C++ code:
    //creation of JVM
    HRESULT Java::CreateJavaVMdll()
         HRESULT HRv = S_OK;
    char classpath[1024];
         jint res;
         if(blog)     this->oDebugLog->Printf("CreateJavaVMdll()");
         strcpy(classpath,"-Djava.class.path="); /*This tells jvm that it is getting the class path*/
         strcat(classpath,getenv("PATH"));
         strcat(classpath,";D:\\Projects\\RingRing\\MMSComposer;C:\\Progra~1\\j2sdk1~1.1_0\\lib");     //;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mail.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\activation.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mmspade.jar
         //------Set Options for virtual machine
         options[0].optionString = "-Djava.compiler=NONE"; //JIT compiler
         options[1].optionString = classpath;                                        //CLASSPATH
         //------Set argument structure components
         vm_args.options = options;
         vm_args.nOptions = 2;
         vm_args.ignoreUnrecognized = JNI_TRUE;
         vm_args.version = JNI_VERSION_1_4;
         /* Win32 version */
         HINSTANCE hVM = LoadLibrary("C:\\Program Files\\j2sdk1.4.1_01\\jre\\bin\\client\\jvm.dll");
         if (hVM == NULL){
              if(blog) oDebugLog->Printf("Can't load jvm.dll");
              return E_FAIL;
         if(blog) oDebugLog->Printf("jvm.dll loaded\n");
         LPFNDLLFUNC1 func = (LPFNDLLFUNC1)GetProcAddress(hVM, "JNI_CreateJavaVM");
         if(!func){
              if(blog)     oDebugLog->Printf("Can't get ProcAddress of JNI_CreateJavaVM");
              FreeLibrary(hVM);     hVM = NULL;
              return E_FAIL;
         if(blog)     oDebugLog->Printf("ProcAddress found");
         res = func(&jvm,(void**)&env,&vm_args);
         if (res < 0) {
    if(blog)     oDebugLog->Printf("Can't create JVM with JNI_CreateJavaVM %d\n",res);
    return E_FAIL;
         if(blog)     oDebugLog->Printf("JVM created");
         return HRv;
    //finding Comverse10 class:
    HRESULT CALLAS MMSComposer::InitializeJNI(void)
         HRESULT HRv=E_FAIL;
         DWORD T=0;
         try
              if(blog)     oDebugLog->Printf("\nInitializeJNI()");
              bJVM = FALSE;
              jni = new Java(oDebugLog);
              if(jni->CreateJavaVMdll()!=S_OK){
                   if(blog)     oDebugLog->Printf("CreateJavaVMdll() failed");     
                   return HRv;
              jclass jcls = jni->env->FindClass("Comverse10");
              if (jcls == 0) {
    if(blog)     oDebugLog->Printf("Can't find Comverse10 class");
                   jclass jcls2 = jni->env->FindClass("test");
                   if (jcls2 == 0) {
                        if(blog)     oDebugLog->Printf("Can't find test class");
                        return HRv;
                   if(blog)     oDebugLog->Printf("test class found %08x",jcls2);
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 class found %08x",jcls);
              jmethodID mid = jni->env->GetMethodID(jcls , "<init>", "()V");
              if (mid == 0) {
                   if(blog)     oDebugLog->Printf("Can't find Comverse10() constructor");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10() constructor found");
              jobject jobj = jni->env->NewObject(jcls,mid);
              if(jobj==0)
                   if(blog)     oDebugLog->Printf("Can't construct a Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 object constucted");
              //Create Global reference, so java garbage collector won't delete it
              jni->jobj_comv = jni->env->NewGlobalRef(jobj);
              if(jni->jobj_comv==0)
                   if(blog)     oDebugLog->Printf("Can't create global reference to Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("global reference to Comverse10 object %08x created",jni->jobj_comv);
              bJVM=TRUE;
              HRv=S_OK;
         }     catch( IDB * bgError ) { throw bgError->ErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T); }
              catch(...) { throw IDB::NewErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T ); }
              return HRv;

    >
    I would guess that the real problem is that that the
    exception you are catching is not in the class path
    that you are defining.Thanks jschell, that was indeed the case.
    I don't have the docs, but I would guess that
    FindClass() only returns null if an exception is
    thrown. And you are not checking for the exception.
    Which would tell you the problem.Ok, i'll remember that. But what with exceptions thrown in my java code, the documents say
    // jthrowable ExceptionOccurred(JNIEnv *env);
    // Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception
    so, what if the java code throws an exception and catches it, will i be able to see that in my c++ code with ExceptionOccurred ?
    or
    should the java method be declared to throw the exception (and not catch it inside the method)
    Again, thank you for your help, it's greatly appreciated !

  • Jar files are not read from HDD

    Hi,
    we are facing a problem while trying to read jar files from Hard disk using CVM. we could able to read the file and the number of bytes read exactely matches with the file size. but while trying to use JNI (*env)->FindClass it is returns 0. Some times it returns an error "inflateFully: ZIP_Read". however we could able to read a small jar file which is of 2 kb and display some graphics. is it the problem with size?? our application is 80kb.Can some one help us in fixing this.
    Profile: PBP/CDC
    Note:
    Sam

    Step 6 makes your third party jars available during runtime on your server since you put the dependency to runtime. I don't think you need/can reference your j2ee server dc in the portalapp.xml.
    Summary of the link I sent you:
    1. Create an External Library DC
    2. Copy all of the Jars I needed to the libraries folder of this DC
    3. Create two Public Parts (right click on the jar files in Package Explorer)
          i) compilePart (with purpose compilation)
          ii) assemblyPart (with purpose assembly)
    4 Create a new DC of type J2EE Server Component / Library
    5. Add a Used DC to the J2EE Library, reference the compilePart from previous step, and set Dependency type to Build
    6. Add another Used DC, reference the assemblePart, this time select both Build and Runtime Dependency Types
    7. Build and deploy.
    Br
    Göran

  • Z/OS Java under WLM stopped working

    We are running WBIFN 1.1 on Z/OS 1.4. It uses DB2 V7 at RSU0512. The java runs under stored procedures, was working at install, but now we get:
    java.lang.ExceptionInInitializerError
    Here are the full messages:
    DSNX961I DSNX9WLS ATTEMPT TO PERFORM JNI FUNCTION FindClass 576
    FAILED FOR STORED PROCEDURE . SSN= D2KT PROC= D2KTWLM ASID=
    01EF CLASS= METHOD= ERROR INFO=
    java.lang.ExceptionInInitializerError
    pq76769 version of DSNX9JVM
    opening stdin, stdout, and stderr files in directory /tmp/java
    JVM classpath option string before translate for JVM:
    '-Dibm.jvm.shareable.application.class.path=/var/mq/wbiftst:/usr/lpp/dbms/db2t/classes'
    JVM trusted.middleware.class.path before translate for JVM:
    '-Dibm.jvm.trusted.middleware.class.path=/usr/lpp/dbms/db2710/d2kt/classes/db2j2classes.zip'
    libpath after setenv/getenv: /usr/lpp/dbms/db2710/d2kt/lib:/usr/lpp/java/IBM/J1.3/bin:/usr/lpp/java/IBM/J1.3/bin/classic
    JVM properties file string before translate for JVM:
    '-Xoptionsfile=/var/mq/wbiftst/jvmsp'
    turning on JVM debugging with options:
    -Dibm.jvm.events.output=/tmp/java/resetEvents.txt
    -Dibm.jvm.unresettable.events.level=max
    error loading JDBC driver
    toString string from error is: java.lang.ExceptionInInitializerError
    Return parm is -15
    can anyone help?

    The recently released Java 7 Update 11 has been blocked by Apple through its XProtect anti-malware feature in OS X.
    Oracle issued the latest update to Java earlier this month to fix a serious zero-day security flaw. The threat was so serious that the U.S. Department of Homeland Security had recommended that all Java 7 users disable or uninstall the software until a patch was issued.
    Apple took action on its own and quietly disabled the plugin through its OS X anti-malware system. And as noted by MacGeneration on Thursday, Apple has again updated its OS X XProtect list, this time to block Java 7 Update 11.
    Because Oracle has yet to issue a newer version of Java that addresses any outstanding issues, Mac users are prevented from running Java on their system.
    Over the last few years, Apple has moved to gradually remove Java from OS X. The Mac maker dropped the Java runtime from the default installation for OS X 10.7 Lion when the operating system update launched in 2010. Java vulnerabilities have been a common exploit used by malicious hackers looking to exploit the OS X platform.
    Most notably, the "Flashback" trojan that spread last year was said to have infected as many as 600,000 Macs worldwide at its peak. Apple addressed the issue by releasing a removal tool specifically tailored for the malware, and also disabled the Java runtime in its Safari web browser starting with version 5.1.7.
    Javascript should not be disabled (it has nothing to do with Java).

  • Trying to run wls in ecplise

    Has any one seen smtg simillar to this? I am trying to run wls 6.1 as a
    plugin to eclipse. I suspect there can be a problem with the plugin
    classloader? Funny thing is that the class not found below really does not
    exist in weblogic.jar...
    Starting WebLogic Server ....
    The WebLogic Server did not start up properly.
    Exception raised: weblogic.management.configuration.ConfigurationError -
    with nested exception:
    [java.lang.ClassNotFoundException:
    weblogic.management.descriptors.ejb11.AdminServerMBean]
    java.lang.ClassNotFoundException:
    weblogic.management.descriptors.ejb11.AdminServerMBean
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:195)
    at weblogic.management.internal.Helper.findClass(Helper.java:729)
    at
    weblogic.management.internal.Helper.getAdminOrConfigMBeanInfo(Helper.java:10
    2)
    at
    weblogic.management.internal.ConfigurationMBeanImpl.<init>(ConfigurationMBea
    nImpl.java:103)
    at weblogic.management.AdminServer.<init>(AdminServer.java:110)
    at weblogic.management.Admin.initialize(Admin.java:216)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:354)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:197)
    at weblogic.Server.main(Server.java:35)
    at com.objectlearn.wlserver.integration.Server$1.run(Server.java:55)
    at java.lang.Thread.run(Thread.java:484)
    --------------- nested within: ------------------
    weblogic.management.configuration.ConfigurationError - with nested
    exception:
    [java.lang.ClassNotFoundException:
    weblogic.management.descriptors.ejb11.AdminServerMBean]
    at
    weblogic.management.internal.Helper.getAdminOrConfigMBeanInfo(Helper.java:11
    7)
    at
    weblogic.management.internal.ConfigurationMBeanImpl.<init>(ConfigurationMBea
    nImpl.java:103)
    at weblogic.management.AdminServer.<init>(AdminServer.java:110)
    at weblogic.management.Admin.initialize(Admin.java:216)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:354)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:197)
    at weblogic.Server.main(Server.java:35)
    at com.objectlearn.wlserver.integration.Server$1.run(Server.java:55)
    at java.lang.Thread.run(Thread.java:484)
    Reason: Fatal initialization exception

    01. Save the AppleScript code as an 'Application Bundle', via 'Script Editor's 'File, Save As...' menu items' 'File Format:' popup buttons' 'Application Bundle' menu item.
    02. In 'Finder' - '<control>' click (or right click, if using a multiple button mouse) on your just saved 'Application Bundle' application, and select the 'Show Package Contents' menu item. A window containing a folder 'Contents' will appear.
    03. Double click on the 'Contents' folder. A Window, titled 'Contents' will appear.
    04. Using 'Property List Editor' (installed when installing 'Xcode') open the file 'Info.plist'. A window titled 'Info.plist' will appear.
    05. Click on the disclosure triangle (which is pointing to the right) to the left of 'Root'. The disclosure triangle will point down, and the contents of 'Root' displayed.
    06. Click on 'Root'; the 'New Sibling' button will be renamed 'New Child' and will become enabled ... or ... Click on any item below 'Root'; the 'New Sibling' will become enabled.
    07. Click on the 'New Child' or 'New Sibling' button.
    08. Enter 'LSUIElement' (without the single quote marks), and then press either the '<tab>' or '<return>' key. The entry may jump to a new position.
    09. Locate the 'LSUIElement' entry row (listing), and under the 'Value' column click twice, enter '1' (without the single quote marks), and finally press the '<return>' key.
    You should now see (under 'Property' 'Class' 'Value' respectively) ...
    LSUIElement String 1
    10. Close the 'Info.plist' window. A drop down sheet will appear. Click on the 'Save' button.
    11. Quit 'Property List Editor'.

  • Java.io.File give incorrect chinese filenam when using javaw.exe

    I am running Chinese Win2000 Pro (SP2) with jre1.3.1 installed. If I use javaw.exe to run my application, java.io.File does not give the correct filename for chinese filename when I use it to run through a directory, though all English filenames show correctly.
    When the same program is run by java.exe instead of javaw.exe, the program runs with no problem and all chinese name are obtained successfully from java.io.File. Does anyone know the reason behind this ?
    I need to use javaw.exe since I am invoking Java from VC++. I don't want a black command prompt window to pop up behind my java application. Please help.

    Hi,
    I am sorry for not replying to ur query. Infact I am facing my own problem and after reading your problem I thought you could help me out in it because you are already successful in invoking java from VC++.
    My problem is that I want to invoke java class from VC++ in such a way that I want to capture the stdout of java class that I invoke from VC++ and use it in VC++. Let me explain first thing first. I am not able to invoke java class from withing vc++. I have looked at JNI help on SUN site but it is giving me lots of compilation error when I include JNI.h in my VC++ program. If you could help me out in this problem, it would be great.
    Thanks in advance.
    Regards
    Rakesh

Maybe you are looking for

  • Filter does not work with *.jsp URL pattern???

    Hi All, I am, by no means, very good at JSF or Java. I have looked at various forum posts on here for ways to implement a security filter to intercept requests to pages that first require one to be logged in, and if not, redirect them to the login pa

  • How do I reset the P1 button on a GX630?

    Hi, I searched here and didnt find anything on this, and though I have been to every MSI linked or suggested I cant seem to find the US manual.  So lets try here.  I have a new GX630 and I set the P1 button to an incorrect program link.  I would simp

  • Report Viewer Dynamic Parameter List not showing a complete list of values

    Hi, I have installed the crystal report runtime 13.0.1.220 for framework 4.0 in a 64-bit windows 7 professional server. I have an aplication that opens crystal reports using the crystal report viewer control for visual studio 2010, also version 13.0.

  • Import/export properties of multiple numeric limit steps

    Hello I have a question to the property loader and the import/export tool in TestStand 3.5. When I want to export the limits of a sequence with multiple numeric steps with the import/export tool, I press the Limits button to include the limits into t

  • Organizational Forms Library FORM LOAD FAILS for one user

    I have a user who is unable to pull up any of the forms listed in the Organizational Forms Library under the Developer Tab within Outlook 2010. Any other person on the same PC has no issues with the same thing. The user in question does not have any