• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not able to access java variables after calling native functions

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.">
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic