Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot instanciate an array of native type #112

Closed
stevielavern opened this issue Oct 5, 2015 · 5 comments
Closed

Cannot instanciate an array of native type #112

stevielavern opened this issue Oct 5, 2015 · 5 comments

Comments

@stevielavern
Copy link
Contributor

Hi,

How can I instanciate an array of native Java type, say "int" ?
The goal would be to be able to pass it to a method that will write to this array, something similar to this :

var intArray = /* ??? allocate java int array ??? */;
this.fillMethod.call(this, intArray, intArray.length);
send('data', intArray);

Thank you,

@marc1006
Copy link

marc1006 commented Oct 5, 2015

You mean a primitive array (int[])?

Use

var intArray = [1, 2, 3];
...

Update:
Could you use a Java method that returns an array?

var intArray = [1,2,3];
intArray = klass.staticFillMethod(intArray);
send('data', intArray);

@stevielavern
Copy link
Contributor Author

No, in my case I cannot use a method that return an array, my method only fills the buffer passed as parameter.

As you suggested first, I tried to simply instantiate a JS array (var intArray = new Array(size); or var intArray = [1, 2, 3];) and pass it as is, but it is left untouched.

@marc1006
Copy link

marc1006 commented Oct 5, 2015

One possibilty would be to create a wrapper class in Java so you could load it with Java.openClassFile(...).load().

Java.openClassFile('classes.dex').load();
const helperClass = Java.use("....helperClass");

But I think the preferred way would be something like that (but it isn't currently implemented)

const intArray = Java.primitiveArray("int[]", [1,2,3]);
klass.fillMethod(intArray);

@stevielavern
Copy link
Contributor Author

Ok, thanks a lot for your answer.
This is indeed not the preferable way, but could be a usable workaround.

I'll update my post later when I use it.

@oleavr oleavr closed this as completed Jan 19, 2017
@awakened1712
Copy link

@stevielavern any update please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants