gpt4 book ai didi

java - ConcurrentModificationException - 无法启动 Activity

转载 作者:行者123 更新时间:2023-12-01 09:01:57 25 4
gpt4 key购买 nike

在 Crashlytics 中发生崩溃,我无法重现并且不知道它发生在哪里。在下面发布所有收到的日志。

Fatal Exception: java.lang.RuntimeException 
Unable to start activity ComponentInfo{.main.MainActivity}: java.util.ConcurrentModificationException
Caused by java.util.ConcurrentModificationException
java.util.ArrayList$ArrayListIterator.next (ArrayList.java:573)
android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.restoreInstanceState (NavigationMenuPresenter.java:587)
android.support.design.internal.NavigationMenuPresenter.onRestoreInstanceState (NavigationMenuPresenter.java:191)

从日志中可以看到NavigationMenuPresenter和NavigationMenuAdapter是android.support.design.internal中的类。从它的名称来看,它似乎与抽屉导航菜单和一些 ArrayList 有关(如果我错了,请纠正我)。尝试恢复菜单状态时是否发生错误?

这是创建导航菜单的代码

private void setupDrawer(Toolbar toolbar) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
initAvailabilityChange(navigationView);
initMenuHeaderViews(navigationView);
}

private void initAvailabilityChange(NavigationView navigationView) {
switchItem = navigationView.getMenu().findItem(R.id.availability);
CompoundButton switchView = (CompoundButton) MenuItemCompat.getActionView(switchItem);
switchNew = (Switch) switchView.findViewById(R.id.switchLocation);
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
isOnShift = isChecked;
presenter.onAvailabilityChange(isOnShift, this);
if (isChecked) {
switchItem.setTitle(R.string.availability_on_shift);
} else {
switchItem.setTitle(R.string.availability_off_shift);
}
});
}

private void initMenuHeaderViews(NavigationView navigationView) {
View header = navigationView.getHeaderView(0);
tvName = (TextView) header.findViewById(R.id.tvName);
tvRank = (TextView) header.findViewById(R.id.tvRank);
}

非常感谢您的帮助。

最佳答案

这可能是 ViewGroup 实现的问题。尝试发布一个新的 Runnable。

switchView.post(new Runnable() {
public void run() {
if (isChecked) {
switchItem.setTitle(R.string.availability_on_shift);
} else {
switchItem.setTitle(R.string.availability_off_shift);
}
}
});

关于java - ConcurrentModificationException - 无法启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41595826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com