Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

call java from c++: where to put class

 
 
Gordon Beaton
Guest
Posts: n/a
 
      08-17-2005
On 17 Aug 2005 01:56:50 -0700, http://www.velocityreviews.com/forums/(E-Mail 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.

/gordon

--
[ 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
 
 
 
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      08-17-2005
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
#endif

#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");
exit(1);
};

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 =
env->GetStaticMethodID(cls,"main","([Ljava/lang/StringV");

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.


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

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

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

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 java.io.FileOutputStream.writeBytes ...
JNI]
This is a test.
This is invokeSimplified7.
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# Internal Error (455843455054494F4E530E43505000FF), pid=3704,
tid=4064
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_02-b09 interpreted mode,
sharing)
# An error report file with more information is saved as
hs_err_pid3704.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
---------------------------------------------------------------------------------------------------------------------------------

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

 
Reply With Quote
 
 
 
Reply

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? 1230987za@gmail.com 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



Advertisments