surfaceview + glsurfaceview + framelayout

痴心易碎 提交于 2019-12-03 01:18:01

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 = new GLSurfaceView(this);

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

This is very simple actually...if you want to define your view in XML you just have to implement

Public GLSurfaceView(Context context, AttributeSet attrs) {
...
super(context, attrs);
}

instead of GLSurfaceView(Context context)

That's the one that gets called automatically when the view is initialized from the XML. I had the same problem and that's how it was fixed.

Found out how to solve it... via the java way... just use addContentView instead of using xml.... well at least its solved. :)

bala singareddy

I actually did that here in this SO link which provides a complete implementation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!