Help

Hello,

I am currently learning JNI and I have come across a problem. I need some advice on it.

My Java File : Addition.java

class Addition

{

public native void add(int a, int b);

static

{

System.loadLibrary("addition");

}

public static void main (String ax[])

{

try

{

int a = Integer.parseInt(ax[0]);

int b = Integer.parseInt(ax[1]);

System.out.println("Native Method called");

new Addition().add(a,b);

}

catch (Exception e)

{

System.out.println(e);

}

}

}

When I run the javac command on this file,it gets compiled.When I run the javah -jni command on it it creates the following header file

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class Addition */

#ifndef _Included_Addition

#define _Included_Addition

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class:Addition

* Method:add

* Signature: (II)V

*/

JNIEXPORT void JNICALL Java_Addition_add

(JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus

}

#endif

#endif

My C method file : AdditionImpl.c

# include <jni.h>

# include <stdio.h>

# include "Addition.h"

JNIEXPORT void JNICALL Java_Addition_add (JNIEnv *env, jobject obj, jint a, jint b)

{

int x;

x = a+b;

printf(x);

}

The entire program gets compiled perfectly. I am using J2SDK1.3 and VC 6.0 software on Windows 2000 platform. However when I run the command

java Addition 2 3

it throws the following exception :

# An EXCEPTION_ACCESS_VIOLATION exception has been detected in native code outsi

de the VM.

# Program counter=0x10001587

Can someone please point out my mistake.

[1956 byte] By [abhiSD] at [2007-9-26 6:36:02]
# 1
Tryprintf("%d\n", x); instead ofprintf(x);
p53043 at 2007-7-1 15:50:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...