android glsurface 闪屏,在null对象引用上的android.opengl.GLSurfaceView $GLThread.surfaceCreated()’...
我试图使用GLSurface来显示自定义视图.
我的xml
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.letsense.matrixtest.MainActivity">
android:layout_width="300dp"
android:layout_height="300dp"
android:id="@+id/my_surface_view"
/>
我的主要
package net.letsense.matrixtest;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
/**
* Created by borislegovic on 03/11/2017.
*/
public class Main extends Activity {
private int mPositionHandle;
private int mColorHandle;
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
// mGLView = new MyGLSurfaceView(this);
// mGLView = findViewById(R.id.my_surface_view);
//mGLView.setEGLContextClientVersion(2);
// mGLView = new MyGLSurfaceView(this);
// setContentView(mGLView);
}
@Override
protected void onPause() {
// The following call pauses the rendering thread.
// If your OpenGL application is memory intensive,
// you should consider de-allocating objects that
// consume significant memory here.
super.onPause();
// mGLView.onPause();
}
@Override
protected void onResume() {
// The following call resumes a paused rendering thread.
// If you de-allocated graphic objects for onPause()
// this is a good place to re-allocate them.
super.onResume();
// mGLView.onResume();
}
}
奇怪的是我没有对surfaceView对象做任何事情,它仍然给我这个崩溃:
java.lang.NullPointerException:尝试在空对象引用上调用虚方法’void android.opengl.GLSurfaceView $GLThread.surfaceCreated()’
在android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:524)
解决方法:
您的GLSurfaceView未初始化,您需要初始化它.
首先创建类MyGLRenderer:
class MyGLRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
}
然后将其添加到OnCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGLView = (GLSurfaceView) this.findViewById(R.id.my_surface_view);
mGLView.setRenderer(new MyGLRenderer());
}
您可以阅读有关OpenGL ES here的更多信息.
标签:android,opengl-es
来源: https://codeday.me/bug/20190727/1550854.html
android glsurface 闪屏,在null对象引用上的android.opengl.GLSurfaceView $GLThread.surfaceCreated()’...相关推荐
- android glsurface 闪屏,浅谈SurfaceView与GLSurfaceView
什么是Surface 让我们看看Surface的官方介绍: Handle onto a raw buffer that is being managed by the screen composito ...
- 设置android应用闪屏图片_Android实现启动页面(闪屏页面)
不难发现,我们手机上的很多app都有启动页面,例如打开简书App在显示主页文章前会有一个启动页面,如下所示: 简书启动页面 随后是一个广告页面,最后才进入到主页去. 那么我们自己怎么实现这个效果呢?下 ...
- Android Splash闪屏页秒开 Activity白屏、Activity黑屏问题
本文转自严振杰的博客: http://blog.csdn.net/yanzhenjie1003 今天在处理项目中闪屏界面的时候,遇到程序第一次开启会出现白屏大约2秒左右,然后再执行闪屏,故找到该篇文章 ...
- android 闪屏页处理_一种Android闪屏页实现方法
为什么会有闪屏页 记得很久之前,那时候android手机才刚刚出来,我们学校工作室里手机游戏开发相关的还更多的是window phone,可能很多人没有见过,就是跟电脑一样有开始菜单那种.那时候工作室 ...
- import android.view.window;,尝试在空对象引用上调用虚拟方法‘android.view.Window$回调...
尝试在空对象引用上调用虚拟方法'android.view.Window$回调-android.view.Window.getCallback()' 当我SplashActivity打开LoginAct ...
- Android之分屏模式解析(上)
上手了Android N Preview,第一个不能错过的新特性就是App分屏的支持.Android7.0原生系统就可以支持两个App横屏并排或者竖屏上下摆放了.第二个新特性就是在Android TV ...
- Android 9闪屏页面适配问题
闲谈 距离上一篇博客已经两个月的时间了,一是年底的工作任务确实加重了一些,二是自己也有些懈怠了--让自己写博客的时间为其他事情让步.好在昨天任务完成,今天放松的休息了一上午,觉得还是要做点什么,来庆祝 ...
- 小米mix2s基于Android,闪电速度!小米MIX2S已经用上基于Android P的MIUI
昨天8月7日谷歌正式发布了Android P正式版,谷歌旗下的Pixel系列智能手机已经支持升级,除此之外Android之父的Essential手机也在第一时间升级到Android P,于是网友们纷纷 ...
- Android studio录屏按钮不能用怎么办,Android多态实现原理
再点击OK 这时候其实就能感觉不对劲了,还没开始录呢,怎么视频都保存好了呢? 找到该视频文件: 发现该视频文件大小是 0 字节,空欢喜一场. 于是我又打开了genymotion 中的一个模拟器: 继续 ...
最新文章
- php 企业微信指令回调借款_企业微信外部联系人回调事件
- ios 界面间跳转方法总结
- 罚函数法求解约束问题最优解
- 软件工程 工具之二—— PowerDesigner v12(四)
- ​【机器学习】交通数据的时间序列分析和预测实战
- 计算机系统 学习笔记(0)南京大学(一)第一周
- 最先进单插槽专业绘图解决方案
- Objective-C中的面向对象编程
- Oracle的锁表与解锁
- cesium 动态水面效果
- 他是浙大 19 岁大一新生,三个月斩获 WWDC 19 奖学金!
- Android小知识10则(下)
- 让 ASP.NET JS验证和服务端的 双验证 更简单
- 定时让电脑进入休眠状态
- 小程序授权登录,后台发送链接,得到参数。
- mapabc全国兴趣点、商户数据、poi数据,一共1490多万条,包含地址、电话、经纬度、类别...
- BIM标准丨深圳市住房和建设局关于印发《房屋建筑工程招标投标建筑信息模型技术应用标准》
- 哪上班 | 好工作近在咫尺
- 假如杨笠吐槽程序员。。。
- 当拓普遇上SAP,展翅翱翔的雄鹰飞向了更高的天空