By tripatano
on Thu, 04/18/2013 - 16:45
In my project, I have to pass my intiger variable from my one java class to ImageTarget.cpp class. Is there any way to see these variable's value from ImageTarget.cpp class. Because I have a loop game and each turn this variable has different value. And I have to see this variable's valur from ImageTarget.cpp class.
Thanks for you help.
Passing one variable from java to c++
Hi,
one simple way is to Log the variable using the LOG function (see examples of usage of the LOG function in ImageTargets.cpp;
for instance to log an integer, you can write:
LOG( "My integer is: %d ", myIntegerVariable);
Passing one variable from java to c++
But I have the catch Java class's integer value than use it in the ImageTarget.cpp class.
Passing one variable from java to c++
Ok, so, if I understand correctly, you want to know how to implement a native method to pass down a variable from Java to C++, right ?
That's quite simple to do:
Passing one variable from java to c++
I have access my variable with this sentence from all of my java class;
MainScreen.number.marker
Passing one variable from java to c++
Hi, you also need to call the printInteger() function somewhere in your Java code, i.e. you need to put a line like this somewhere:
printInteger ( umut );
Passing one variable from java to c++
Hi, I did what you said but I have a problem like this now;
I have to convert string to integer in this function; (marker is my global integer in cpp)
(I think that variable named value is String because of %s)
Passing one variable from java to c++
Hi,
if your goal is to print an integer value (i.e. if your Java variable is an integer, as I understood from your original post), then you simply need to adjust the printInteger function code as follows:
Passing one variable from java to c++
Actually I want to assign coming integer value to my cpp variable. I dont want to print it.
I decleared an integer variable like this in cpp;
...
Passing one variable from java to c++
Hi, maybe try to initialize your marker variable to some value, for instance (in your global declaration):
int marker = -1;
Passing one variable from java to c++
Thank you very much I did it but now I have a problem when calling onDestroy() function think. In logcat I have an error like this;
Passing one variable from java to c++
Hi, you should never call onDestroy() explicitly; just start the new activity.
Passing one variable from java to c++
But when I dont call onDestroy function I have this situation;
I have a game project like this.
Passing one variable from java to c++
Ok, but then you should simply deinitialize QCAR when you start "puzzle" (but not calling the entire onDestroy());
Passing one variable from java to c++
How can I deinitialize QCAR in the other class? With this command?
QCAR.deinit();
Passing one variable from java to c++
Hi,
you can use the same de-initialization code that you find in ImageTargets.java;
if you need to call it from a different class, you can create a public method in ImageTargets.java, for instance
public void deinitQCAR()
{
Passing one variable from java to c++
Hi, I did what you said but I cant reach this method from another class. As you said i wrote it public but I cant reach it with these two commands;
deinitQCAR();
or
ImageTargets.deinitQCAR();
Passing one variable from java to c++
You need to pass a reference to ImageTargets class to your calling class, store the reference in a member variable of your class and then call it like this (suppose your class is called "MyClass"):
Passing one variable from java to c++
Thank you for your help but when I do that it gives an error like that;
Passing one variable from java to c++
Have you called setImageTargetsRef() method passing the ImageTargets instance before running the other code ?
Passing one variable from java to c++
OK, I solve the problem. Thank you very much for your help. You are the best.
Passing one variable from java to c++
Glad to help.