1

Is it possible to declare an object of a native class (in c++) in java (android sdk)?

jmj
  • 237,923
  • 42
  • 401
  • 438
StarDust
  • 846
  • 1
  • 13
  • 26

3 Answers3

1

The only solution would be to create a JNI lib that would serve as a communication layer between your Java and C++ code.

That Lib would need to :

1- Contain methods that receive your needed Java Objects as JObject. (lookup this post for how to use the jobject : how to pass java class instance as a parameter to JNI method?

2- Request your C++ objects to your native code

3- Do whatever you need to do with both objects.

Hope it helps ;)

Cheers !

Community
  • 1
  • 1
oberthelot
  • 1,310
  • 1
  • 11
  • 23
0

Native classes which be declared and defined in c++.

However when you use JNI, you define a Java class with native method and generate C code from this to implement using javah

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

No. The only objects that Java recognizes are Java objects.

The JNI approach allows you to create a native method for a Java class, and a JNI method implemented in C / C++ can create other C / C++ objects. However, there is no way that you can pass such an object back to Java so that the Java code can use it directly.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216