gpt4 book ai didi

android - 表面 View + glsurfaceview + 框架布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:02 26 4
gpt4 key购买 nike

我是 java 和 OpenGL 的新手。

我正在尝试让相机预览屏幕能够同时显示 3d 对象。已经在api 演示,我想将示例的代码组合在api演示就足够了。但不知何故它不起作用。强制我在启动时关闭并且错误被称为空指针异常(exception)。有人可以和我分享我哪里出了问题以及如何解决从那里开始。如图所示,我是如何组合代码的下面:

我的概览.xml


<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.opengl.GLSurfaceView
android:id="@+id/cubes"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<SurfaceView
android:id="@+id/camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>

我的概览.java


import android.app.Activity; 
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.Window;
public class MyOverView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// camera view as the background
SurfaceView cameraView = (SurfaceView) findViewById(R.id.camera);
cameraView = new CameraView(this);
// visual of both cubes
GLSurfaceView cubesView = (GLSurfaceView) findViewById(R.id.cubes);
cubesView = new GLSurfaceView(this);
cubesView.setRenderer(new CubeRenderer(false));
// set view
setContentView(R.layout.myoverview);
}
}

GLSurfaceView.java


import android.content.Context; 
class GLSurfaceView extends android.opengl.GLSurfaceView {
public GLSurfaceView(Context context) {
super(context);
}
}

注意:

  • 我没有列出其余文件,因为它们只是api演示。 cameraView 引用 camerapreview.java 示例而 CubeRenderer 指的是 CubeRenderer.java 和 Cube.java例子。任何帮助,将不胜感激。

  • 抱歉,没有意识到由于格式错误导致编码不正确。

最佳答案

使用 .xml 时出现空指针异常的原因是因为您实际上是在 Java 代码中创建新 View .. 而不是使用 .xml 文件中您可能已传入属性的 View (如果你确实传递了属性......)..新 View 显然会有一个空值..因此抛出一个空指针异常......例如 -

cubesView = new GLSurfaceView(this);

如果您已经在包含 FrameLayout 的 .xml 文件中创建了 View ,则代码中实际上不需要。

关于android - 表面 View + glsurfaceview + 框架布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2108600/

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