2016-07-29 66 views
0

我用GLSurfaceView但發生NullpointerException條件使用GLSurfaceView在Android

我想展示使用GLSurfaceview

相機預覽我必須使用GLSurfaceView

最近,發生NullPointerException異常代碼

MainActivity。

public class CameraMainActivity extends FragmentActivity { 

    private GLSurfaceView glview; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     . 
     . 
     . 
     glview = (GLSurfaceView) findViewById(R.id.framelayoout_network); 
     VideoRendererGui.setView(glview, null) ; 
    } 

(VideoRendererGui是webRtc

VideoRendererGui.class

public class VideoRendererGui implements Renderer { 
    private static VideoRendererGui instance = null; 
    private static Runnable eglContextReady = null; 

    public static void setView(GLSurfaceView surface, Runnable eglContextReadyCallback) { 
    instance = new VideoRendererGui(surface); 
    eglContextReady = eglContextReadyCallback; 
} 

和activity_main.xml中

<android.opengl.GLSurfaceView 
     android:layout_width="200dp" 
     android:layout_height="300dp" 
     android:id="@+id/framelayout_network"> 
    </android.opengl.GLSurfaceView> 

logcat的

java.lang.NullPointerException 
     at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:523) 
     at android.view.SurfaceView.updateWindow(SurfaceView.java:572) 
     at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:232) 
     at android.view.View.dispatchWindowVisibilityChanged(View.java:8004) 
     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077) 
     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077) 
     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077) 
     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077) 
     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077) 
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1233) 
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) 
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 
     at android.view.Choreographer.doCallbacks(Choreographer.java:574) 
     at android.view.Choreographer.doFrame(Choreographer.java:544) 
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5001) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
     at dalvik.system.NativeStart.main(Native Method) 

我不知道爲什麼會發生NullPointerException異常

也許,使用GLSurfaceView需要條件?

請給我建議

謝謝。

回答

0
VideoRendererGui.setView(glview, null) ; 

應該改變,

VideoRendererGui.setView(glview, new Runnable() { 
     @Override 
     public void run() { 
      Log.d(TAG, "log something what you want..."); 
     }) ; 
相關問題