Article View: borland.public.jbuilder.java.language
Article #8220JNI Invoker crashing
From: Calvin R. Smith
Date: Fri, 13 Apr 2001 19:00
Date: Fri, 13 Apr 2001 19:00
109 lines
3500 bytes
3500 bytes
I've written a little C program to run a class which works great until the
program quits at which point it crashes trying to read 000000000001
I'm using JDK 1.2.2 and Visual C 6.0
Can some please point me in the right direction?
Calvin
here is the Java Code:
public class Prog
{
public static void main(String[] args)
{
System.out.println("Hello out there");
}
}
and here is my C code:
#include <jni.h>
#include <stdio.h>
#include <windows.h>
main()
{
JavaVMOption options[1];
JavaVMInitArgs vm_args;
JavaVMAttachArgs args;
JavaVM *jvm=(JavaVM*)0;
JNIEnv *env;
jobjectArray argsForMain;
jclass cls;
jstring jstr;
jmethodID mid;
long result;
char *s;
printf("hi\n");
memset(&vm_args,0,sizeof(vm_args));
printf("after mem set\n");
JNI_GetDefaultJavaVMInitArgs(&vm_args);
s = malloc(100);
printf("num of options: ");
sprintf(s,"%d", vm_args.nOptions);
printf(s);
printf("\n");
free(s);
printf("after free\n");
options[0].optionString =
"-Djava.class.path=C:\\neboinstall\\StartNebo\\java";
printf("after setting classpath\n");
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_FALSE;
args.version = JNI_VERSION_1_2;
args.name = "user";
args.group = NULL;
result = JNI_CreateJavaVM(&jvm,(void**)&env, &vm_args);
if (result == JNI_ERR)
{
printf("Error invoking the Java Virtual Machine\n");
}
else
{
cls = (*env)->FindClass(env,"Prog");
if (cls == NULL)
{
printf("error finding main class");
}
else
{
(*env)->ExceptionClear(env);
mid = (*env)->GetStaticMethodID(env, cls, "main",
"([Ljava/lang/String;)V");
if (mid == 0)
{
printf("can't find main");
}
else
{
jstr = (*env)->NewStringUTF(env, "");
if (jstr == 0)
{
printf("Out of memory");
}
else
{
argsForMain = (*env)->NewObjectArray(env, 0,
(*env)->FindClass(env, "java/lang/String"), jstr);
if ( argsForMain == NULL)
{
printf("Out of memory");
} }
else
{
(*env)->CallStaticVoidMethod(env, cls, mid,
argsForMain);
(*jvm)->DestroyJavaVM(jvm);
}
}
}
}
}
}
Technical Details
Message-ID:
<3ad74d2c$1_2@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,ba31b21847aa8ccc,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-04-13 12:14:20 PST Reply-To: "Calvin R. Smith" <calvinrsmith@hotmail.com> From: "Calvin R. Smith" <calvinrsmith@hotmail.com> Newsgroups: borland.public.jbuilder.java.language Subject: JNI Invoker crashing Date: Fri, 13 Apr 2001 13:00:32 -0600 Lines: 112 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 207.201.104.90 Message-ID: <3ad74d2c$1_2@dnews> X-Trace: dnews 987188524 207.201.104.90 (13 Apr 2001 12:02:04 -0700) Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews