我的绘图应用程序有问题。当我退出绘图活动时(例如,使用返回按钮),我遇到以下错误。我看过这些帖子,但似乎没有任何帮助。拜托,如果您能看一下我的drawingsurface活动,那将会有很多意义,因为我一直在努力使它起作用!非常感谢 :)

错误:

03-25 13:41:36.760: E/AndroidRuntime(6642): FATAL EXCEPTION: Thread-423
03-25 13:41:36.760: E/AndroidRuntime(6642): java.lang.IllegalArgumentException
03-25 13:41:36.760: E/AndroidRuntime(6642):     at android.view.Surface.nativeUnlockCanvasAndPost(Native Method)
03-25 13:41:36.760: E/AndroidRuntime(6642):     at android.view.Surface.unlockCanvasAndPost(Surface.java:457)
03-25 13:41:36.760: E/AndroidRuntime(6642):     at android.view.SurfaceView$4.unlockCanvasAndPost(SurfaceView.java:812)
03-25 13:41:36.760: E/AndroidRuntime(6642):     at com.ecp.drawing.DrawingSurface$DrawThread.run(DrawingSurface.java:80)


DrawingSurface的主要代码:

    public void run() {
        Canvas canvas = null;
        while (_run){
            if(isDrawing == true){
                try{
                    canvas = mSurfaceHolder.lockCanvas(null);
                    if(mBitmap == null){
                        mBitmap =  Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
                    }
                    final Canvas c = new Canvas (mBitmap);

                    c.drawColor(0, PorterDuff.Mode.CLEAR);
                    canvas.drawColor(0, PorterDuff.Mode.CLEAR);


                    commandManager.executeAll(c,previewDoneHandler);
                    previewPath.draw(c);

                    canvas.drawBitmap (mBitmap, 0,  0,null);
                } finally {
                    mSurfaceHolder.unlockCanvasAndPost(canvas);
                }


            }

        }

    }


已经有一个表面破坏功能:

public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    boolean retry = true;
    thread.setRunning(false);
    while (retry) {
        try {
            thread.join();
            retry = false;
        } catch (InterruptedException e) {
            // we will try it again and again...
        }
    }
}

最佳答案

我猜想lockCanvas引发了一个异常,该异常将canvas设置为null。异常将执行发送到名为finallyunlockCanvasAndPost子句,该子句引发了新的异常。新的例外掩盖了旧的例外。

(这看起来像是4.3中的错误,但此问题是在4.3发布之前发布的。)

关于java - 绘图表面,unlockCanvasAndPost和IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15770467/

10-14 07:44