本文介绍了GLSurfaceView.onDetachedFromWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题与GLSurfaceView,当我开始我的活动我做GLSurfaceView这一行code看不见的:

I have a little issues with an GLSurfaceView, when I start my Activity I make the GLSurfaceView invisible with this line of code:

glSurface.setVisibility(View.INVISIBLE);

在这段时间里,我开始一个AsyncTask的,这将下载来自网络的图片,在这个时候,如果我preSS后退按钮我遇到这种异常:

During this time I start an AsyncTask which downloads an Image from network, at this time, if I press the back button I meet this Exception:

java.lang.NullPointerException
E/AndroidRuntime( 1847):    at android.opengl.GLSurfaceView.onDetachedFromWindow(GLSurfaceView.java:530)
E/AndroidRuntime( 1847):    at android.view.View.dispatchDetachedFromWindow(View.java:6033)
E/AndroidRuntime( 1847):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847):    at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1630)
E/AndroidRuntime( 1847):    at android.view.ViewRoot.doDie(ViewRoot.java:2671)
E/AndroidRuntime( 1847):    at android.view.ViewRoot.die(ViewRoot.java:2641)
E/AndroidRuntime( 1847):    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
E/AndroidRuntime( 1847):    at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436)
E/AndroidRuntime( 1847):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3684)
E/AndroidRuntime( 1847):    at android.app.ActivityThread.access$2900(ActivityThread.java:125)
E/AndroidRuntime( 1847):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
E/AndroidRuntime( 1847):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1847):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1847):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1847):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1847):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1847):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1847):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidR

怎么了?

推荐答案

这可能是因为你没有设置渲染器。

It could be that you haven't set the renderer.

从 Android的参考:

 onDetachedFromWindow ()... Must not be called before a renderer has been set.

所以,如果你设定渲染器(即使你没有渲染任何东西),这可能会回避的问题。

So, if you set the renderer (even if you aren't rendering anything yet), this might avoid the issue.

这篇关于GLSurfaceView.onDetachedFromWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 14:27