gpt4 book ai didi

java - 绘图表面、unlockCanvasAndPost 和 IllegalArgumentException

转载 作者:行者123 更新时间:2023-11-29 03:35:28 25 4
gpt4 key购买 nike

我的绘图应用程序有问题。当我离开绘图 Activity 时出现以下错误(例如使用返回按钮)。我看过这些帖子,但似乎没有任何帮助。拜托,如果你能看看我的绘图表面 Activity ,那将意义重大,因为我已经尝试让它工作了一段时间!非常感谢:)

错误:

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


}

}

}

已经有一个surface destroyed函数:

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 设置为空。该异常将执行发送到 finally 子句,该子句调用了 unlockCanvasAndPost,它引发了一个新的异常。新异常掩盖了旧异常。

(这看起来有点像 4.3 中的错误,但这是在 4.3 出来之前发布的。)

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com