S
ss
hi frnds i want to return an integer array fron c prog to java how do i
proceed with it .....i tried with some code but is is not
working......please tell me wat to do and where i m wrong
my code is
class IntArray {
private native int[] sumArray(int[] arr);
public static void main(String[] args) {
IntArray p = new IntArray();
int arr[] = new int[10];
int newarr[]=new int[10];
System.out.println("previous values of newarr");
for(int j=0;j<10;j++)
{arr[j]=j;
System.out.println(arr[j]);
}
newarr=p.sumArray(arr);
//for (int i = 0; i < 10; i++)
// {
//arr = i;
//}
// int sum = p.sumArray(arr,newarr);
System.out.println("new values of newarr");
try{for(int j=0;j<10;j++)
System.out.println(newarr[j]);
}
catch(NullPointerException np){}
System.out.println("value of sum");
// System.out.println("sum = " + sum);
}
static {
System.loadLibrary("IntArray");
}
}
#include<stdio.h>
#include<jni.h>
#include"IntArray.h"
JNIEXPORT jintArray JNICALL Java_IntArray_sumArray
(JNIEnv *env, jobject obj, jintArray arr)
{
jint buf[10];
jint i, sum = 0;
(*env)->GetIntArrayRegion(env, arr, 0, 10, buf);
for (i = 0; i < 10; i++) {
buf= buf+2;
printf("%d",buf);
}
return buf;
}
it is printing the values in c program but it is not retuning the
newarr
proceed with it .....i tried with some code but is is not
working......please tell me wat to do and where i m wrong
my code is
class IntArray {
private native int[] sumArray(int[] arr);
public static void main(String[] args) {
IntArray p = new IntArray();
int arr[] = new int[10];
int newarr[]=new int[10];
System.out.println("previous values of newarr");
for(int j=0;j<10;j++)
{arr[j]=j;
System.out.println(arr[j]);
}
newarr=p.sumArray(arr);
//for (int i = 0; i < 10; i++)
// {
//arr = i;
//}
// int sum = p.sumArray(arr,newarr);
System.out.println("new values of newarr");
try{for(int j=0;j<10;j++)
System.out.println(newarr[j]);
}
catch(NullPointerException np){}
System.out.println("value of sum");
// System.out.println("sum = " + sum);
}
static {
System.loadLibrary("IntArray");
}
}
#include<stdio.h>
#include<jni.h>
#include"IntArray.h"
JNIEXPORT jintArray JNICALL Java_IntArray_sumArray
(JNIEnv *env, jobject obj, jintArray arr)
{
jint buf[10];
jint i, sum = 0;
(*env)->GetIntArrayRegion(env, arr, 0, 10, buf);
for (i = 0; i < 10; i++) {
buf= buf+2;
printf("%d",buf);
}
return buf;
}
it is printing the values in c program but it is not retuning the
newarr