错误:无法访问android.view.SurfaceView

时间:2011-10-27 10:49:42

标签: java android android-ndk

我正在关注Android NDK的初学者指南。

我有点卡住了。恢复的问题是:我有一个带有一些本机方法的Java类。 当我尝试使用javah创建C头文件并键入:

javah -jni com.droidonfire.DroidOnFire

它返回

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

问题出在哪里?

由于

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");
}

}

1 个答案:

答案 0 :(得分:2)

在调用javah时需要指定-classpath参数,请参阅文档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

在你的情况下,你需要将android.jar添加到你的类路径。

答案here也有类似的问题。