我有来自以下的堆栈跟踪Firebase Craslytics:致命异常:java.lang.NullPointerException尝试在空对象引用com.accenture.vrmobile.BaseActivity.setDrawerVisibility(BaseActivity.java:497)上调用虚拟方法'void android.widget.ImageView.setVisibility(int)'它使用以下方法报告崩溃: public void setDrawerVisibility(Boolean visible) { if (mButtonActionBarLeft == null) mButtonActionBarLeft = (ImageView) findViewById(R.id.button_actionbar_left); if (mButtonActionBarRight == null) mButtonActionBarRight = (ImageView) findViewById(R.id.button_actionbar_right); if (visible) { mButtonActionBarLeft.setVisibility(View.VISIBLE); //crashes at this line mButtonActionBarRight.setVisibility(View.VISIBLE); } else { mButtonActionBarLeft.setVisibility(View.INVISIBLE); mButtonActionBarRight.setVisibility(View.INVISIBLE); }}我之前曾发生过这次崩溃,因此将以下几行添加到了方法中:if (mButtonActionBarLeft == null) mButtonActionBarLeft = (ImageView) findViewById(R.id.button_actionbar_left); if (mButtonActionBarRight == null) mButtonActionBarRight = (ImageView) findViewById(R.id.button_actionbar_right);但是它仍然崩溃和报告nullPointerException。mButtonActionBarLeft和mButtonActionBarRight是用于打开/关闭导航抽屉的按钮。我不知道为什么会这样。也许有人对此有经验?谢谢!PS我从来没有能够重现这种崩溃,这种情况很少发生。我只有来自的堆栈跟踪Firebase。
3 回答
HUWWW
TA贡献1874条经验 获得超12个赞
试试这个
if (visible) {
if(mButtonActionBarLeft.getVisibility()==View.INVISIBLE)
mButtonActionBarLeft.setVisibility(View.VISIBLE);
if(mButtonActionBarRight.getVisibility()==View.INVISIBLE)
mButtonActionBarRight.setVisibility(View.VISIBLE);
} else {
if(mButtonActionBarLeft.getVisibility()==View.VISIBLE)
mButtonActionBarLeft.setVisibility(View.INVISIBLE);
if(mButtonActionBarRight.getVisibility()==View.VISIBLE)
mButtonActionBarRight.setVisibility(View.INVISIBLE);
}
添加回答
举报
0/150
提交
取消