• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a string in C++ and sending to Java using JNI  RSS feed

 
Preet Rams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im developing a plugin in eclipse which reads from a C++ file. I have const char * data in my C++ file and I have the following program to read into Java, but error occurs while reading the string part, while it works fine for long and integer. Can anybody point out what the mistake is?




 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

Two things:

1. You say, "but error occurs." Keep in mind that ItDoesntWorkIsUseless(←click). You need to TellTheDetails(←click) about exactly went wrong. Copy/paste the exact, complete error message, and indicate clearly which line caused it.

2. If the error occurs during execution of that code, then it probably has nothing to do with Java. Let us know if that's the case, and one of the mods can move this thread to this site's C/C++ forum. Otherwise, if the error occurs in the Java that tries to use this code, then you'll need to provide more details about your overall JNI or JNA setup.

Good luck!
 
Preet Rams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jeff Thanks for the reply! The C++ part works fine and compiles without any errors. When I try to read the string data in Java using Eclipse, I get a fatal error for exception access violation. So this is a problem with Java.
 
Preet Rams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JNI function which calls the testhandler is:



And in Java, I call the set_handler using

where the 's' stands for the string to be read
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preet Rams wrote:@Jeff Thanks for the reply! The C++ part works fine and compiles without any errors.


Just to be clear: It compiles AND you tested its functionality, outside of Java? Or by "works and compiles", do you just mean that it compiles? That's a crucial distinction.

When I try to read the string data in Java using Eclipse, I get a fatal error for exception access violation. So this is a problem with Java.


Again: Copy/paste the exact, complete error message.

It's 2:30 a.m. where I am, so I'm off to get reacquainted with my pillow soon, and I don't really know much about JNI anyway, but with any luck, with those last to bits of information, somebody else will be able to come in and give you some guidance toward fixing the problem.

Good luck!
 
Preet Rams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By compiles, I mean it just compiles. And I have not tested it outside Java environment.

The exact error message that I get is:

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006da5a770, pid=1504, tid=2876
JRE version: 6.0_41-b02
Java VM: Java HotSpot(TM) 64-Bit Server VM (20.14-b01 mixed mode windows-amd64 compressed oops)
Problematic frame:
V [jvm.dll+0x24a770]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!