android - Opengl es 2.0 null pointer from findViewByID -


i'm trying set application using opengl es 2.0, using following tutorial: http://androidblog.reindustries.com/a-real-open-gl-es-2-0-2d-tutorial-part-1/

so able successfuly compile application , run in emulator, launches, app crashes... have 2 layout files: activity_main.xml:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.openglproject1.mainactivity"     tools:ignore="mergerootframe" /> 

and fragment_main.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/gamelayout"     android:layout_width="fill_parent"     android:layout_height="fill_parent"> </relativelayout> 

from investigation turned out that:

relativelayout layout = (relativelayout) findviewbyid(r.id.gamelayout); 

in oncreate mainactivity's method:

protected void oncreate(bundle savedinstancestate) {          // turn off window's title bar         requestwindowfeature(window.feature_no_title);          // super         super.oncreate(savedinstancestate);          // fullscreen mode         getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);          // create our surfaceview our opengl here.         glsurfaceview = new glsurf(this);          // set our view.         setcontentview(r.layout.activity_main);          // retrieve our relative layout our main layout set our view.         relativelayout layout = (relativelayout) findviewbyid(r.id.gamelayout);          // attach our surfaceview our relative layout our main layout.         relativelayout.layoutparams glparams = new relativelayout.layoutparams(relativelayout.layoutparams.match_parent, relativelayout.layoutparams.match_parent);         layout.addview(glsurfaceview, glparams);     } 

returns null pointer... whole code used presented in link above if wish can paste here, though it's big bit. i'm wondering if need additional file gamelayout or anything?... it's confusing me please don't hesitate offer tips! grateful help!

you set activity layout

setcontentview(r.layout.activity_main); 

the source is:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.openglproject1.mainactivity"     tools:ignore="mergerootframe" /> 

however try access r.id.gamelayout in activity, said layout specified in fragment_main.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/gamelayout"             //over here     android:layout_width="fill_parent"     android:layout_height="fill_parent"> </relativelayout> 

so error lies in here.

change line setcontentview(r.layout.activity_main); setcontentview(r.layout.fragment_main); , let me know if works?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -