簡體   English   中英

在Android上使用GLSurfaceView的條件

[英]condition to use GLSurfaceView on android

我使用GLSurfaceView但發生NullpointerException

我想顯示相機預覽以使用GLSurfaceview

我必須使用GLSurfaceView

最近,發生nullpointerException代碼

MainActivity.class

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>

日志貓

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需要條件?

請給我建議

謝謝。

VideoRendererGui.setView(glview, null) ;  

應該改為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM