Article View: comp.lang.java.programmer
Article #673JNI someone could help me
From: Juan Pedro Barbancho Manchon
Date: Wed, 21 Jan 1998 00:00
Date: Wed, 21 Jan 1998 00:00
104 lines
3622 bytes
3622 bytes
Dear sir,
I use the JNI sun example, It compile and build a .exe, but no run well.
Additionally, I try use the JRE demo. Need urgent help. Please, thank
in avance.
The code:
////////////////////INVOKE.C///////////////////
/* * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information. *
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */
#include <jni.h>
main()
{
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and
beyond */
vm_args.version = 0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
cls = (*env)->FindClass(env, "Prog.class");
if (cls == 0) {
fprintf(stderr, "Can't find Prog class\n");
exit(1);
}
mid = (*env)->GetStaticMethodID(env, cls, "main",
"([Ljava/lang/String;)V");
if (mid == 0) {
fprintf(stderr, "Can't find Prog.main\n");
exit(1);
}
jstr = (*env)->NewStringUTF(env, " from C!");
if (jstr == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
args = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env,
"java/lang/String"), jstr);
if (args == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
(*env)->CallStaticVoidMethod(env, cls, mid, args);
(*jvm)->DestroyJavaVM(jvm);
}
The Java program:
//////////////////////////PROG.JAVA////////////////////////////////
public class Prog {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
The error:
can't fing Prog class
The . is in the classpath, Prog.class is in . directory.
Please, send me faster, Thank you
mail: ct2bamaj@uco.es
JuanP
--
--------------------------------------------------
Nombre y apelllidos:
Juan Pedro Barbancho Manch�n
Organizaci�n:
CTI
http://www.uco.es/grupos/cti
E-mail:
ct2bamaj@uco.es
Java Senior Programmer
Technical Details
Message-ID:
<34C61B25.DA1B712@uco.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10a146,c70f1367b7fa1035,start X-Google-Attributes: gid10a146,public X-Google-Thread: 1116f3,c70f1367b7fa1035,start X-Google-Attributes: gid1116f3,public X-Google-Thread: 113ae9,c70f1367b7fa1035,start X-Google-Attributes: gid113ae9,public From: Juan Pedro Barbancho Manchon <ct2bamaj@uco.es> Subject: JNI someone could help me Date: 1998/01/21 Message-ID: <34C61B25.DA1B712@uco.es> X-Deja-AN: 318115828 Content-Transfer-Encoding: 8bit To: ANAYA <java@anaya.es>, jni@java.sun.com X-Priority: 3 (Normal) Content-Type: text/plain; charset=iso-8859-1 Organization: CTI Mime-Version: 1.0 Newsgroups: comp.lang.java.programmer,comp.lang.java.help,es.comp.lenguajes.java