surfaceview + glsurfaceview +的FrameLayout [英] surfaceview + glsurfaceview + framelayout

查看:422
本文介绍了surfaceview + glsurfaceview +的FrameLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个新的(Java和OpenGL的),所以请大家多多包涵,如果 问题的答案是简单的。 :)

I'm new at this (java and opengl) so please bear with me if the answer to the question is simple. :)

我试图让一个摄像头preVIEW屏幕的能力 同时显示3D对象。通过样品已经离开了吗 API的演示,我觉得结合$ C $下的例子 API的演示就足够了。但不知何故,它不工作。在部队我 在启动时关闭,错误被提及作为空指针 例外。可能有人和我分享我上哪儿去错了,怎么 从那里出发。我怎么做了结合,为code为如图所示 如下:

I'm trying to get a camera preview screen with the ability to display 3d objects simultaneously. Having gone through the samples at the api demos, I thought combining the code for the the examples at the api demo would suffice. But somehow its not working. The forces me to shut down upon startup and the error is mentioned as null pointer exception. Could someone share with me where did I go wrong and how to proceed from there. How I did the combination for the code is as shown below:

myoverview.xml

myoverview.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>

myoverview.java

myoverview.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

GLSurfaceView.java

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

请注意:

  • 我没有列出文件的剩余部分,​​因为它们只是副本 API的演示。该cameraView是指相机preview.java例子 和CubeRenderer指CubeRenderer.java和Cube.java 例。任何帮助将是AP preciated因为我一直停留在此的一对夫妇 天:P谢谢

  • I didnt list the rest of the files as they are just copies of the api demos. The cameraView refers to the camerapreview.java example and the CubeRenderer refers to the CubeRenderer.java and Cube.java example. Any help would be appreciated as I've been stuck at this for a couple of days :p Thanks

对不起,没有意识到该编码是不合时宜的,由于格式错误。 :P

Sorry, didnt realise that the coding was out of place due to formatting mistakes. :p

推荐答案

用的.xml工作时,你得到一个空指针异常的原因是因为乌拉圭回合的实际创建在你的java code新的视野..而不是使用从.xml文件那些你也许会已通过的属性(如果u没有传递属性,是..)..新的View显然有一个空值。因而抛出一个空指针异常...的例如 -

the reason you are getting a null pointer exception when working with .xml is because ur actually creating new Views in your java code.. instead of using the ones from the .xml file to which you might have passed in properties(if u did pass in properties that is..).. the new View would obviously have a null value.. thus throwing a null pointer exception... for example --

cubesView =新GLSurfaceView(本);

cubesView = new GLSurfaceView(this);

其实并不需要在code,如果你已经创建了一个包含查看的.xml文件的FrameLayout ..

is actually not needed in the code if you already created the View in the .xml file containing FrameLayout..

这篇关于surfaceview + glsurfaceview +的FrameLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆