Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 9th, 2005, 01:00 AM
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get a String from JNI?

I want to get a returned String from JNI, but I don't know how to do it, my code are follows:
public class MyNative{
 public String test1(String s){
   return test11(s);
 private native String test11(String s);
   System.loadLibrary( "MyNative" );
 public static void main( String[] args ){
    MyNative obj = new MyNative();
    String c=obj.test1("abc");

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class MyNative */
#ifndef _Included_MyNative
#define _Included_MyNative
#ifdef __cplusplus
extern "C" {
 * Class: MyNative
 * Method: test11
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
JNIEXPORT jstring JNICALL Java_MyNative_test11
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus

#include <stdio.h>
#include "MyNative.h"
JNIEXPORT jstring JNICALL Java_MyNative_test11
  (JNIEnv *env, jobject obj, jstring s){
   //How to realize return String to Java???,such as return a string "hello world",how to realize this function,please give example code.

Thanks in advance!

Reply With Quote
  #2 (permalink)  
Old December 19th, 2005, 03:34 PM
Registered User
Join Date: Dec 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

return (*env)-> NewStringUTF(env,"Hello World");

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
apache tomcat and JNI elixiradeel Apache Tomcat 0 June 5th, 2008 09:55 PM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
its about the jni API ogriddmut Dreamweaver (all versions) 1 June 29th, 2004 03:05 AM

All times are GMT -4. The time now is 07:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.