从dialogclass调用一个函数

时间:2018-02-14 12:08:06

标签: java android

这是我的 DialogClass

public android.app.Dialog onCreateDialog(Bundle savedInstanceState) {

    DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface argo0, int arg1) {
            switch (arg1){

                case 0:
                    selection=(String) items[arg1];
                    break;
                case 1:
                    selection=(String) items[arg1];
                    break;
                case 2:
                    selection=(String) items[arg1];
                    break;
                case 3:
                    selection=(String) items[arg1];
                    break;
                case 4:
                    selection=(String) items[arg1];
                    break;
                case 5:
                    selection=(String) items[arg1];
                    break;
            }
        }
    }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Camera2BasicFragment q= new Camera2BasicFragment();
            q.c();

        }
    });
    return builder.create();
    // return super.onCreateDialog(savedInstanceState);
}
}

我从父类Camera2BasicFragment调用函数c,但它返回错误。

java.lang.NullPointerException: Attempt to invoke virtual method 
'android.graphics.SurfaceTexture 
com.example.android.camera2basic.AutoFitTextureView.getSurfaceTexture()' on 
a null object reference

如何在对话框中调用函数???

该行发生错误     SurfaceTexture texture = mTextureView.getSurfaceTexture();

类c

public void c() {

    try {
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;

        // We configure the size of default buffer to be the size of camera preview we want.
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

        // This is the output Surface we need to start preview.
        Surface surface = new Surface(texture);

0 个答案:

没有答案