1

I'm following a guide for beginners with android NDK.

And I'm a little stuck. The resumed problem is: I have an Java class with some native methods. When I try to create the C Header File using javah and type:

javah -jni com.droidonfire.DroidOnFire

And it returns

Error: cannot access android.view.SurfaceView
class file for android.view.SurfaceView not found

Where is the problem?

Thanks

The class DroidOnFire:

public class DroidOnFire extends SurfaceView implements SurfaceHolder.Callback{

private boolean mEnabled;
private Paint mTextPaint;
private Paint mTextOffPaint;
private Paint mCanvasPaint;
private Bitmap  mEffect;
private Canvas mEffectCanvas;

public DroidOnFire(Context context, AttributeSet attrs) {
    super(context, attrs);
    getHolder().addCallback(this);
    mEnabled= false;
    initialize();
}

public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    mEffect= Bitmap.createBitmap(width,200,Bitmap.Config.ARGB_8888);
    mEffectCanvas= new Canvas(mEffect);
}

public void surfaceCreated(SurfaceHolder holder) {

    setKeepScreenOn(true);
    setWillNotDraw(false);
    mTextPaint= new Paint();
    mTextPaint.setTextSize(32.0f);
    mTextPaint.setColor(Color.WHITE);
    mTextOffPaint = new Paint();
    mTextOffPaint.setColor(Color.BLACK);
    mTextOffPaint.setTextSize(32.0f);
    mCanvasPaint= new Paint();
    mEnabled= true;

}

public void surfaceDestroyed(SurfaceHolder holder) {
    mEnabled= false;
    mEffect.recycle();
    mEffect=null;
    mEffectCanvas=null;

}

@Override
public void draw(Canvas canvas) {
    if (mEnabled){
        String lMessage=getMessage();
        mEffectCanvas.drawText(lMessage, 0, 32, mTextOffPaint);
        updateFire(mEffect);
        canvas.drawBitmap(mEffect, 0, 0,mCanvasPaint);
        canvas.drawText(lMessage, 0, 32, mTextPaint);
        initialize();
    }
}

private native void initialize();
private native String getMessage();
private native void updateFire(Bitmap pBitmap);
static {
    System.loadLibrary("fire");
}

}

Addev
  • 31,819
  • 51
  • 183
  • 302

1 Answers1

2

You need to specify a -classpath argument when invoking javah, see the docs here.

classpath path
    Specifies the path javah uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by semi-colons. Thus the general format for path is:
       .;<your_path>
    For example:
       .;C:\users\dac\classes;C:\tools\java\classes

In your case you need to add android.jar to your classpath.

There is a similar question with an answer here.

Community
  • 1
  • 1
sbridges
  • 24,960
  • 4
  • 64
  • 71