string->char* [former Re: core dump]
Martin Aliger
martin_aliger@email.cz
Tue Nov 5 01:06:00 GMT 2002
Hi list again,
> > #include <java/lang/Math.h>
> > int main()
> > {
> > jint i=java::lang::Math::round((jfloat)2.3);
> > return 0;
> > }
>
> This is the main method, so the VM isn't initialized yet. Also, the Math
> class may not be initialized. See
> http://gcc.gnu.org/onlinedocs/gcj/Invocation.html for a similar example
> using the CNI invocation interface.
It already works great! Thanks once more.
Now I'm using this code:
-----
int main()
{
printf("Hello from C\n");
try {
_Jv_CreateJavaVM(NULL);
_Jv_AttachCurrentThread(NULL,NULL);
w::main();
_Jv_DetachCurrentThread();
} catch (java::lang::Throwable* t)
{
jstring clsname=t->getClass()->getName();
char cbuf[1024];
int cl=clsname->length();
if(cl>1024) cl=1024;
_Jv_GetStringUTFRegion(clsname,0,cl,cbuf);
cbuf[cl]=0;
jstring jmsg=t->getLocalizedMessage();
char buf[1024];
if(jmsg) {
int l=jmsg->length();
if(l>1024) l=1024;
_Jv_GetStringUTFRegion(jmsg,0,l,buf);
buf[l]=0;
} else {
buf[0]=0;
}
printf("Java %s exception: %s\n",cbuf,buf);
}
return 0;
}
-----
It works, but that conversion from jstring to char* is not very convinient. Is there any (helper) method to do this? Or rather convert into wchar_t or similar (not jchar)? I just want to return error message to C++ caller and it could (should!) not be aware if Java classes.
Regards,
Martin
BTW: good work! GCJ seems to be much more mature that I (and many others) think! AWT library is not main interest of many developers and IMHO it should not be part of gcc itself (rather external library to depend on)
______________________________________________________________________________
Email.cz -----> Vaše emailová schránka zdarma.
http://www.Email.cz <------------Pošta zdarma!
More information about the Java
mailing list