Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > call java from c++: where to put class

Thread Tools

call java from c++: where to put class

Gordon Beaton
Posts: n/a
On 17 Aug 2005 01:56:50 -0700, Removed) wrote:
> I do not think that there is errors in my source code.

I don't agree.

> I made a test and the source code is following:

I was referring to your C++ code, not the Java code. I thought that
was clear from the example in my earlier reply.


[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Reply With Quote
Posts: n/a
I think that you are correct, now I guess #that this error is caused by
CallStaticVoidMethod() in C++ codes. What I have done to prove this is:
I simplied the C++ codes and Java codes, as following:

/*for C++,debugged with Visual C++ 6.0*/
// invoke.cpp

#ifndef __cplusplus
#define __cplusplus

#include "jni.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#pragma comment (lib,"E:\\Programme\\Java\\jdk1.5.0_02\\lib\\jvm.l ib")

void main() {

JavaVM *jvm;
JNIEnv *env;

JavaVMInitArgs vm_args;
JavaVMOption options[3];

options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = "-Djava.classpath=.";
options[2].optionString = "-verbose:jni";

vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 3;
vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_TRUE;

jint res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");

jclass cls = env->FindClass("DemoMain");
if (cls == 0) printf("Sorry, I can't find the class");

jmethodID get_main_id;

if(cls != NULL)
get_main_id =

if(get_main_id != NULL )
jclass string = env->FindClass("java/lang/String");
jobjectArray args = env->NewObjectArray(0,string, NULL);

fprintf(stdout, "This is invokeSimplified6.\n");
env->CallStaticVoidMethod(cls, get_main_id, args);
fprintf(stdout, "This is invokeSimplified7.\n");

}// end IF.

}// end IF.

fprintf(stdout, "Java VM destory\n");
}//end main.

************************************************** ************************************************** **********

In the main() of Java codes, there are only 2 sentences:
System.out.println ("This is a test");

IOTest is another java class located in a different directory. There
are only 2 sentences in print2Lines():
System.out.println ("Line1");
System.out.println ("Line2");

I simply these classes, so no parameter was transmitted in different
methods or classes.
I run the c++ codes, the output is like this:
__________________________________________________ ______________________________
This is invokeSimplified6.
[Dynamic-linking native method ...
This is a test.
This is invokeSimplified7.
# An unexpected error has been detected by HotSpot Virtual Machine:
# Internal Error (455843455054494F4E530E43505000FF), pid=3704,
# Java VM: Java HotSpot(TM) Client VM (1.5.0_02-b09 interpreted mode,
# An error report file with more information is saved as
# If you would like to submit a bug report, please visit:

So I know that this error is caused by CallStaticVoidMethod(). But how
to change it so the output is correct?
Thanks a lot.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: c++ class design: where to put debug purpose utility class? Phlip C++ 36 07-02-2008 02:30 PM
Re: c++ class design: where to put debug purpose utility class? Phlip C++ 2 07-01-2008 02:49 AM
class design: where to put debug purpose utility class? C++ 8 06-28-2008 05:14 AM
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM