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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:17:34+00:00 2026-06-04T02:17:34+00:00

Trying to figure out why c++ function call returning an int crashes the whole

  • 0

Trying to figure out why c++ function call returning an int crashes the whole application without any errors/warnings.

Here is working code:


    jint Java_org_ntorrent_DummyTorrentInfoProvider_next(
            JNIEnv * env, jobject obj, jint number)
    {
        jint test = rand();
        __android_log_print(ANDROID_LOG_DEBUG, "HelloNDK!", "rand() = %d", test);

        return number;
    }

And this code crashes application without warnings:


    jint Java_org_ntorrent_DummyTorrentInfoProvider_next(
            JNIEnv * env, jobject obj, jint number)
    {
        jint test = rand();
        __android_log_print(ANDROID_LOG_DEBUG, "HelloNDK!", "rand() = %d", test);

        return number + test;
    }

Before the application crashes i can see my log message(__android_log_print) in log cat

EDIT:
Even if I replace “number + test” with “1” the application still crashing…
It only works if I return “number”…

EDIT#2: Java-side code:


package org.ntorrent;

import java.util.ArrayList;
import java.util.Random;

public class DummyTorrentInfoProvider implements TorrentInfoProvider {

    public native Integer next(Integer number);

    //public Integer next() { return _random.nextInt(); }

    public native void test();

    private Random _random = new Random(100);

    @Override
    public ArrayList getTorrents() {
        test();
        ArrayList torrents = new ArrayList();
        torrents.add(
                new TorrentInfo("test torrent number 1", next(1),  3f, 5f));
        torrents.add(
                new TorrentInfo("test torrent number 2", next(2), 4f, 15f));
        torrents.add(
                new TorrentInfo("test torrent number 555"));
        torrents.add(
                new TorrentInfo("test torrent number 3", next(3), 13f, 5f));
        return torrents;
    }

    static {
        System.loadLibrary("test");
    }
}
  • 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-04T02:17:35+00:00Added an answer on June 4, 2026 at 2:17 am
    jint Java_org_ntorrent_DummyTorrentInfoProvider_next(
        JNIEnv * env, jobject obj, jint number)
    

    and

    public native Integer next(Integer number);
    

    Do not match. An Integer is an Object, while an int is a primitive.

    If your native code uses jint, your java code should use int in the declaration of the native method.

    (If you wish to pass an Integer, you’ll need to treat it as a jobject on the native side, and jump through hoops to access it – it’s probably easier to use int/jint and do any necessary conversion to from Integer in the java side)

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

Sidebar

Related Questions

I'm trying to figure out how to call a c function from an obj-c
I am trying to figure out why my delegate function does not work, any
I am trying to figure out what you call a function that references itself.
I am trying to figure out why my function to open a file is
I'm a newbie with jQuery and I'm trying to figure out this slideToggle function.
I'm trying to figure out just how a particular function works on a Facebook
I am trying to figure out exactly how to implement a callback function which
I'm trying to figure out why when it gets gets to the getLast5Messages function
I'm horrible with regex but i'm trying to figure out how an import function
Trying to figure out how to programmatically access the web pages in the application.

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.