I am creating a demo of a mathematical operation such as addition, subtraction, multiplication and division using the NDK.
I can make a library and get a response from my own code, but the result is not correct, I mean that this is a random static value.
Class Calculator.c
#include <stdio.h>
Calculator.java to load the library and run your own methods.
public class Calculator { static { System.loadLibrary("Calculator"); } public native int add(int a, int b); public native int substract(int a, int b); public native int multiply(int a, int b); public native int devide(int a, int b); }
I use the code below to display the result:
int num1 = Integer.parseInt(txtNumber1.getText().toString().trim()); int num2 = Integer.parseInt(txtNumber2.getText().toString().trim()); tvResult.setText(String.format("%1$d + %2$d is equals to %3$d", num1, num2, mCalculator.add(num1, num2)));
Exit

Dharmendra
source share