Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:58+00:00 2026-06-13T02:14:58+00:00

I have a class written in c++. I want to write a method to

  • 0

I have a class written in c++. I want to write a method to return a string so I can read it from my java class. I’ve tried to do something like:

readstring.cpp:

#include "common.h"
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

/************
 * ReadString *
 ************/

 jstring Java_com_googlecode_leptonica_android_ReadFile__getString(JNIEnv *env, jclass clazz)
{
  jstring result = env->NewStringUTF("My String");
 return result;
}

#ifdef __cplusplus
}
#endif  /* __cplusplus */

Readstring.java:

package com.testjni;

    public class ReadString {

        static {
            System.loadLibrary("lept");
        }

        public String getText(){
            return getString();
        }
        private static native String getString();
    }

Reading string from an activity:

public class TestJNI extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ReadString readString = new ReadString();
        Toast.makeText(this, readString.getText(), Toast.LENGTH_SHORT).show();
    }
}

and stack trace is:

10-16 12:35:09.974: ERROR/AndroidRuntime(12303): FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: getString
at com.testjni.ReadString.getString(Native Method)
at com.testjni.ReadString.getText(ReadString.java:10)
at com.testjni.TestJNI.onCreate(TestJNI.java:13)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:14:59+00:00Added an answer on June 13, 2026 at 2:14 am

    “Java_com_googlecode_leptonica_android_ReadFile__getString”

    here your package is ” com.googlecode.leptonica.android” and class is “ReadFile” and the function is “getString”.

    Actually you didnt mention this function in your code .Please check that.

    use like this

    “Java_com_testjni_ReadString__getString()” in your c code instead of

    “Java_com_googlecode_leptonica_android_ReadFile__getString”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I've written a TypeConverter for. I want to keep
I have a class written in C++ that uses also some definitions from cuda_runtime.h,
I have a class I've written to act like an enumeration: abstract class Enum
I have created dynamic web project. In that I have written one Java class
I have a custom class with a serialize method, and I want to be
I have a java code like this: private class Uploader implements Runnable { //
I've written a class that implements IEnumerable<T> . I have a method that returns
I have a class written in c# which is acting as a wrapper around
I have the following class written by someone else that I'm trying to understand
I have written a class in python that implements __str__(self) but when I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.