Android ViewRoot NullPointerException

时间:2011-06-03 19:13:08

标签: android 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));


    }


}

1 个答案:

答案 0 :(得分:2)

我强烈建议您重复使用视频播放器活动的方式。如果您只想播放视频,请使用VideoView并将其嵌入XML布局中。 您开始活动并窃取其视图的方式看起来像是在尝试解决框架问题,这会导致各种古怪的错误。好像我似乎我不太了解ActivityGroup。不过,我认为这可能会以某种方式简化。