首页 > 解决方案 > Android canvas.save() 和 canvas.restore() 使我的应用程序崩溃

问题描述

我尝试在这样的视图中显示一个画布:

protected void onPostExecute(Canvas canvas){
        Rect rect = new Rect();
        rect.set(0,0,nbColumns*65,nbLines*20);

        View v = activity.findViewById(R.id.viewOfPDF);

        int widthSpec = View.MeasureSpec.makeMeasureSpec(rect.width(), View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(rect.height(), View.MeasureSpec.EXACTLY);
        v.measure(widthSpec, heightSpec);

        v.layout(0, 0, rect.width(), rect.height());
        canvas.save();
        canvas.translate(rect.left, rect.top);
        v.draw(canvas);
        canvas.restore();
    }

但是当我运行我的活动时,我的应用程序出错了。这不是例外:

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 25473 (iondestagiaires), pid 25473 (iondestagiaires)

我这样做了save()restore()就在这一次。

我的观点只是一个简单的观点。

你能帮助我吗?

标签: javaandroidcanvasview

解决方案


单击设置-> 构建、执行、部署-> 部署-> 即时运行。

然后取消选中顶部的“启用即时运行”复选框。


推荐阅读