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 6884293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:29:22+00:00 2026-05-27T05:29:22+00:00

Crash while returning from android ndk function on Samsung Galaxy S2. In my java

  • 0

Crash while returning from android ndk function on Samsung Galaxy S2.
In my java code I call an NDK function, and sometimes (this may be one of 20 random cases) the application hangs (ANR) immediately after returning from NDK. The log says

12-05 04:19:59.760: D/AndroidRuntime(5607): Shutting down VM
12-05 04:19:59.760: W/dalvikvm(5607): threadid=1: thread exiting with uncaught exception (group=0x40015578)
12-05 04:19:59.775: W/dalvikvm(5607): threadid=14: thread exiting with uncaught exception (group=0x40015578)

Sometimes a few lines of java code are executed before this happens. I’ve tried fully clearing the NDK function and removing all params from it to no avail. The function is called from a separate java thread.
On other phones (HTC Desire HD, HTC Legend and others) I have not seen this problem.

This is my java code, which calls ndk function:


    private static native void ndkFunctionN(
            byte[] filePath1N, byte[] filePath2N, 
            byte[] filePath3N, byte[] tmpDirN, JavaClass callerN,
            byte[] param5N, byte[] param6N, byte[] param7N);


    public static void javaFunction(
            File file1, File file2, File file3, String tmpDir, 
            JavaClass caller, String param5, String param6, String param7) 
    {
        try {
            byte[] filePath1N = file1.getPath().getBytes("UTF-8");
            byte[] filePath2N = file2.getPath().getBytes("UTF-8");
            byte[] filePath3N = file3.getPath().getBytes("UTF-8");
            byte[] tmpDirN = tmpDir.getBytes("UTF-8");
            byte[] param5N = appClassName.getBytes("UTF-8");
            byte[] param6N = param6.getBytes("UTF-8");
            byte[] param7N = param7.getBytes("UTF-8");

            mergeAndDumpN(
                    filePath1N, filePath2N, filePath3N, tmpDirN, 
                    caller, param5N, param6N, param7N);
            } catch (UnsupportedEncodingException e) {
                MyLog.e(e);
            }
    }

This is the C++ code:

    JNIEXPORT void JNICALL Java_com_package_name_ClassName_ndkFunctionN (
      JNIEnv* env, jobject thiz,
      jbyteArray filePath1N, jbyteArray filePath2N,
      jbyteArray filePath3N, jbyteArray tmpDirN,
      jobject callerN, jbyteArray param5N,
      jbyteArray param6N, jbyteArray param7N)
    {
    }
  • 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-05-27T05:29:22+00:00Added an answer on May 27, 2026 at 5:29 am

    Perhaps, in your separate thread you are still using the same JNIEnv value as you got in your first thread? You have to call g_JavaVM->AttachCurrentThread(&env, NULL); or something similar to obtain a correct JNIEnv for your other thread. The same way you should then to refind all your classes/methods using that new JNIEnv value

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

Sidebar

Related Questions

While debugging a crash, I came across this issue in some code: int func()
I may be teaching a Java crash-course soon. While it is probably safe to
I am observing a crash while calling the CMemFile::Detach() function The exception with the
While debugging crash in a multithreaded application I finally located the problem in this
While investigating a crash, I came across the following code snippet and immediately recognized
I get a very common crash below from the code below. I thought my
I am facing crash issue in native of my android code. My app is
This is a crash report - its from an ad-hoc tester and I cannot
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I stumbled on a way to crash excel in Workbook_Open while making an .xla

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.