tags:

views:

108

answers:

1

my activity is::

package com.soft;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TestNdk extends Activity {
     TextView txtHello;


    private int m_cAddValue;


    private TestNdk m_cTestNDK;


    private int m_cObj;
    public TestNdk(int i, int j) {
      getSum();
    }

    public native int getSum();

     /** Called when the activity is first created. */
         @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
               setContentView(R.layout.main);



              txtHello = (TextView) findViewById(R.id.txtHello);
              txtHello.setText("hai this is for test");  
              //public TestNdk(int i, int j) ;

              m_cTestNDK = new TestNdk(20 ,30);





              txtHello.setText(m_cObj);

          }

         static{
             System.loadLibrary("TestNDK");
            initIDs();
             }


      }

=============================================================

my header file is ::test.h

#ifndef __TEST_H__
#define __TEST_H__

class MyClass
{
private:
  int   m_cFirstNum;
  int   m_cSecondNum;
public:
  MyClass(int pNum1, int pNum2);
  int getSum();
  int getMult();
  int getSub();
  int getDiv();
};

#endif  //__TEST_H__

=============================================

my cpp file is:: test.cpp

#include "test.h"

MyClass::MyClass(int pNum1, int pNum2)
{
  m_cFirstNum = pNum1;
  m_cSecondNum = pNum2;
}

int MyClass::getSum()
{
  return m_cFirstNum + m_cSecondNum;
}

int MyClass::getMult()
{
  return m_cFirstNum * m_cSecondNum;
}

int MyClass::getSub()
{
  return m_cFirstNum - m_cSecondNum;
}

int MyClass::getDiv()
{
  int lRetVal = 0;
  if(0 != m_cSecondNum)
  {
    lRetVal = m_cFirstNum + m_cSecondNum;
  }
  return lRetVal;
}

plz guide me on this always i am getting the message like ::newInstance failed: no ()

+1  A: 

you really need to do two things:

  1. learn JNI: http://java.sun.com/docs/books/jni/html/jniTOC.html

  2. learn the Android-specific bits: http://developer.android.com/sdk/ndk/1.6_r1/index.html#samples

what you have here isn't even remotely close to how JNI is used, so you should start from the beginning. (it's probably easiest to learn on the desktop first, because there's lots more documentation and examples on the web, and even books on the subject. and the differences between desktop Java JNI and Android JNI are mainly a matter of how exactly to build your code.)

Elliott Hughes