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

  • Home
  • SEARCH
  • 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 8308385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:47:44+00:00 2026-06-08T18:47:44+00:00

i am tying to create jni example with some code but it display error

  • 0

i am tying to create jni example with some code but it display error in logcate

07-30 18:34:48.720: W/dalvikvm(3484): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/org/HelloNDK/HelloNDK;.<clinit>
07-30 18:34:48.740: W/dalvikvm(3484): Class init failed in newInstance call (Lcom/org/HelloNDK/HelloNDK;)
07-30 18:34:48.740: D/AndroidRuntime(3484): Shutting down VM
07-30 18:34:48.760: W/dalvikvm(3484): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-30 18:34:48.810: E/AndroidRuntime(3484): FATAL EXCEPTION: main
07-30 18:34:48.810: E/AndroidRuntime(3484): java.lang.ExceptionInInitializerError
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.Class.newInstanceImpl(Native Method)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.Class.newInstance(Class.java:1429)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.os.Looper.loop(Looper.java:123)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.reflect.Method.invokeNative(Native Method)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.reflect.Method.invoke(Method.java:521)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at dalvik.system.NativeStart.main(Native Method)
07-30 18:34:48.810: E/AndroidRuntime(3484): Caused by: java.lang.UnsatisfiedLinkError: Library libndkfoo not found
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.Runtime.loadLibrary(Runtime.java:461)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at java.lang.System.loadLibrary(System.java:557)
07-30 18:34:48.810: E/AndroidRuntime(3484):     at com.org.HelloNDK.HelloNDK.<clinit>(HelloNDK.java:12)
07-30 18:34:48.810: E/AndroidRuntime(3484):     ... 15 more

code is:

Main Activity(java File)

package com.org.HelloNDK;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;

public class HelloNDK extends Activity {
    /** Called when the activity is first created. */

      static {
            System.out.println("Lib 1");
            System.loadLibrary("libndkfoo");
            System.out.println("Lib 2");
          }

      private native String invokeNativeFunction();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {

             // this is where we call the native code
            String hello = invokeNativeFunction();
            new AlertDialog.Builder(this).setMessage(hello).show();

        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("Error in On Create == >"+e.toString());
        }
    }
}

Android.mk file Code

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# Here we give our module name and source file(s)
LOCAL_MODULE    := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c

include $(BUILD_SHARED_LIBRARY)

ndkfoo.c File code

#include <string.h>
#include <jni.h>
JNIEXPORT jstring JNICALL Java_org_pielot_hellondk_HelloNDK_sayHello(JNIEnv *env, jobject obj) 
{
     return (*env)->NewStringUTF(env, "Hello from native code!");
}

The .SO file is created with

infoware@infoware-PC /cygdrive/d/SecondWorkspace/HelloNDK
$  /cygdrive/d/android-ndk-r8b/ndk-build
Compile thumb  : ndkfoo <= ndkfoo.c
SharedLibrary  : libndkfoo.so
Install        : libndkfoo.so => libs/armeabi/libndkfoo.so

Project Screen for Structure

enter image description here

  • 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-08T18:47:48+00:00Added an answer on June 8, 2026 at 6:47 pm
    1. in your activity: rename private native String invokeNativeFunction();
      to private native String sayHello();
    2. in your c-file : rename
      JNIEXPORT jstring JNICALL Java_org_pielot_hellondk_HelloNDK_sayHello(JNIEnv *env, jobject obj)
      to
      JNIEXPORT jstring JNICALL Java_com_org_hellondk_HelloNDK_sayHello(JNIEnv *env, jobject obj)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple Java app that uses JNI to call some
I am trying to create a simple example with JNI. I am having trouble
I am tying to create a custom alert box with fixed positioning. It works
Trying to create a black line in my view to separate text blocks but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
I'm trying to create a Qt main windows from Java using JNI directly and
I am trying to create a DLL to use it with Java JNI. I
I'm trying to combine some existing Qt code written in C++ with some code
I'm tying to create a class that holds a reference to another classes method.
I am trying to create a JNI wrapper for this windows application called 'Personal

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.