Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to access java variables after calling native functions

 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am running a java program which calls a native C function and returns back. The native code is getting executed but after returning back to the java program, the variables are not identified.
Let me explain,

My java program is like,

psvm(String args[]){
int n=10;
System.out.println("n value is:"+n);
//code for calling the C-Function
System.out.println("back to java program");
System.out.println("n value is:"+n);
//other code
}

When I run this program, the output is,
n value is:10
back to java program


The problem is that the program is not identifying "n" after returning back and the "//other code" is not executed. Also no error or exception is shown.
Can anyone help me.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you us the actual full code of this method? Without those comment place holders.
 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class testingC {

native void testingcores(int int1,int int2);
static {
System.load("C:\\Microsoft Visual Studio 9.0\\VC\\Cprogram.dll");
}
public static void main(String[] args) {
int n=Integer.parseInt(args[1]);
System.out.println("jobs to be created is:"+n);
testingC tc=new testingC();
for(int i=1;i<=n;i++){
tc.testingcores(i,i+(i*100));
}
System.out.println("All jobs are started ");
System.out.println("jobs"+n+"started);
}


java testingC 5 5

then OUTPUT is,
jobs to be created is 5.
All jobs started.

The problem is that when it encounters a variable("n" in this case), it is not recognizing it. So,the last statement is not printed.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code should never cause any problems. All I can think of is some bug in your native code. Can you show the native code for testingcores?
And while you're at it, please Use Code Tags.
 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the C code,


I don't think there is a problem with the C code,
the file is created and data is written correctly.">
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic