这将导致错误:的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));
}
}
你在运行什么Android版本? – Femi 2011-06-03 19:38:07
您是否确认该活动实际开始?这可能是该视图为空。 – Aleadam 2011-06-03 19:40:20
针对Android 2.2。通过检查活动是否开始,你的意思是什么?我已经调试过它,并且我的onCreate被称为该活动。所以我在主UI线程上运行这个,我使用“this”关键字...它是否引用我的LiveTabGroup实例,因为它是我想要的呢?考虑到这一点,我将如何引用特定的活动而不使用“this”? – spentak 2011-06-03 19:47:30