Fragment替换的时候报空指针。

2025-03-06 03:56:22
推荐回答(1个)
回答1:

用这个方法吧,切换第二个fragment的时候,要先把之前那个remove,然后再add进去的
所以建议使用replace,会自己把之前那个移除,再增加,请查看相关api
transaction.replace(id,fragment);