File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes JNI question - c++ objects (global?) and returning arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "JNI question - c++ objects (global?) and returning arrays" Watch "JNI question - c++ objects (global?) and returning arrays" New topic
Author

JNI question - c++ objects (global?) and returning arrays

Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Hi, I am trying to run the native c++ code under android using NDK and JNI but I think this reffers to a JNI problem in general.
I guess I will start with explaining the functionality of my c++ code and then ask how can I transfer this to JAVA android app.

In my c++ code I do more less sth like the following (i don't want to go too specific into details):


So after all operations I have a float array named 'result' which has the size of 'size1'

Now my question Is how to transport this functionality to Android using NDK. MY ideas are:

1. Because I can't make the cppObject in Java application and it must 'remember' the results of each loop iteration I guess the only solution is to declare cppObject as a global in the JNI .cpp file - is this the right approach and how to do this?

2. I am not sure but I guess I have finally discovered how to pass an array of floats from JAVA to C++. Is this correct?


3. How to create a proper JNI function for this part:


So after I run the native method in Java I will have the same array as 'results' with size of 'size1'. So in other word - how to return the float * form c++ to JAVA app through JNI

I am spending hours after hours looking for a solution in the Internet so please can somebody help me?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Let's move this to our Android forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Yeah probably a better place - sorry for the trouble :>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNI question - c++ objects (global?) and returning arrays