spentak
spentak

Reputation: 4747

Android ViewRoot NullPointerException

This causes the error:

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

Not sure what the problem is, here is the trace:

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]  

Here is my code:

    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));


    }


}

Upvotes: 0

Views: 571

Answers (1)

Steve Pomeroy
Steve Pomeroy

Reputation: 10129

I'd highly suggest reworking the way you're using the video player activity. If you just want to play a video, use the VideoView and embed it in an XML layout. The way you're starting an activity and stealing its view looks like you're trying to work around the framework, which is going to lead to all sorts of wacky errors like this.It seems as though I didn't understand ActivityGroups very well. Still, I think this could probably be simplified somehow.

Upvotes: 2

Related Questions