This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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?




 
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]
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!