2011-06-03 73 views
0

這將導致錯誤:的Android的ViewRoot NullPointerException異常

this.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
      ViewGroup.LayoutParams.FILL_PARENT)); 

不知道是什麼問題,這裏是跟蹤:

ViewRoot.draw(boolean) line: 1440 
ViewRoot.performTraversals() line: 1172 
ViewRoot.handleMessage(Message) line: 1736 
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 143 
ActivityThread.main(String[]) line: 4701  
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
Method.invoke(Object, Object...) line: 521 
ZygoteInit$MethodAndArgsCaller.run() line: 860 
ZygoteInit.main(String[]) line: 618 
NativeStart.main(String[]) line: not available [native method] 

這裏是我的代碼:

public class LiveTabGroup extends ActivityGroup implements MoveToScreenNotification.handler 
{ 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     EventBus.subscribe(MoveToScreenNotification.class, this); 

     View view = getLocalActivityManager().startActivity("CameraListView", new Intent(this,CameraListView.class). 
       addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 

     this.setContentView(view); 

    } 

    @Override 
    public void onMoveToScreenNotification(MoveToScreenNotification notif) 
    { 
     if (notif.newScreen == MoveToScreenNotification.SCREEN_MOVIEPLAYER_LIVE) 
     { 
      SugarLoafSingleton.currentCamera.url = notif.videoURL; 
      // Throw UI management on main thread 
      runOnUiThread(new Runnable(){ 
      public void run() 
      { 
       StartPlayer(); 
      } 
      }); 

     } 

    } 

    public void StartPlayer() 
    { 
     View view = getLocalActivityManager().startActivity("VideoPlayer", new Intent(this,VideoPlayerView.class). 
       addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 
     this.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
       ViewGroup.LayoutParams.FILL_PARENT)); 


    } 


} 
+0

你在運行什麼Android版本? – Femi 2011-06-03 19:38:07

+0

您是否確認該活動實際開始?這可能是該視圖爲空。 – Aleadam 2011-06-03 19:40:20

+0

針對Android 2.2。通過檢查活動是否開始,你的意思是什麼?我已經調試過它,並且我的onCreate被稱爲該活動。所以我在主UI線程上運行這個,我使用「this」關鍵字...它是否引用我的LiveTabGroup實例,因爲它是我想要的呢?考慮到這一點,我將如何引用特定的活動而不使用「this」? – spentak 2011-06-03 19:47:30

回答

2

我我強烈建議您改變您使用視頻播放器活動的方式。如果您只想播放視頻,請使用VideoView並將其嵌入到XML佈局中。 你開始一個活動並竊取它的視圖的方式看起來像你正在嘗試解決這個框架,這將導致像這樣的各種古怪的錯誤。看起來好像我不明白ActivityGroup很好。不過,我認爲這可能會以某種方式簡化。

+0

什麼是mediaplayer視圖?我想你的意思是videoview? – MByD 2011-06-03 20:36:08

+0

是的,我的意思是一個視頻視圖。更正了答案文本。 – 2011-06-04 00:53:55

相關問題