Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
绘制位图时未调用Android surfaceview oncreated_Android_Surfaceview_Android Canvas - Fatal编程技术网

绘制位图时未调用Android surfaceview oncreated

绘制位图时未调用Android surfaceview oncreated,android,surfaceview,android-canvas,Android,Surfaceview,Android Canvas,我在SurfaceView.updateWindow中遇到一个空指针异常,我想这是因为我在onDraw中,但从未收到surfaceCreated on the surface。所以有没有办法解决这个问题,或者在直接渲染到位图时强制调用surfacecreated 当在活动中添加为contentview时,此曲面视图将正确呈现。但实际上我想直接将surfaceview渲染为位图,而不在任何地方显示它 SurfaceView构造函数: public ObservationDetailsGraphic

我在SurfaceView.updateWindow中遇到一个空指针异常,我想这是因为我在onDraw中,但从未收到surfaceCreated on the surface。所以有没有办法解决这个问题,或者在直接渲染到位图时强制调用surfacecreated

当在活动中添加为contentview时,此曲面视图将正确呈现。但实际上我想直接将surfaceview渲染为位图,而不在任何地方显示它

SurfaceView构造函数:

public ObservationDetailsGraphicView(Context context) {
    super(context);
    getHolder().addCallback(this);  
}
SurfaceView onDraw:

@Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    LayoutInflater inflater = LayoutInflater.from(c);
    View detailView = inflater.inflate(R.layout.observation_details_graphic_view,null);
    detailView.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    detailView.measure(bmWidth, bmHeight);          
    detailView.layout(0, 0, bmWidth, bmHeight);
    detailView.draw(canvas);  //null pointer exception here
}
呼叫代码:

Bitmap exportBitmap = Bitmap.createBitmap(640, 960, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(exportBitmap);
ObservationDetailsGraphicView view = new ObservationDetailsGraphicView(this);
view.draw(canvas);
我在logcat中看不到任何相关内容,但以下是堆栈的相关部分:

ObservationDetailsGraphicView(SurfaceView).updateWindow(boolean, boolean) line: 473 
ObservationDetailsGraphicView(SurfaceView).dispatchDraw(Canvas) line: 350   
ObservationDetailsGraphicView(View).draw(Canvas) line: 6883 
ObservationDetailsGraphicView(SurfaceView).draw(Canvas) line: 336   

你面临什么问题。。在oncreate中,您正在创建surfaceview,因为它正在发生或通货膨胀中存在一些问题。您面临的问题是。。在oncreate中,您正在创建surfaceview,因为它正在发生或存在通货膨胀问题。。