【问题标题】:Android error java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitleAndroid错误java.lang.NullPointerException:尝试调用虚拟方法'void androidx.appcompat.app.ActionBar.setTitle
【发布时间】:2020-08-05 09:37:01
【问题描述】:

我是 Android 新手。底部导航时显示错误。

错误:

Android 错误 java.lang.NullPointerException:尝试调用虚拟方法 'void androidx.appcompat.app.ActionBar.setTitle


     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page);
        BottomNavigationView navView = findViewById(R.id.nav_view);

        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
    }

【问题讨论】:

标签: android


【解决方案1】:

如果你想显示一个无标题的屏幕,你首先应该删除你的navigation.xml中的android:label:

<fragment
    android:id="@+id/navigation_home"
    android:label="HomeFragment"  //remove this line
    android:name="com.shiwei.fly.ui.home.HomeFragment" />

然后在您的活动中,删除以下代码:

// Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    /*val appBarConfiguration = AppBarConfiguration(setOf(
            R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
    setupActionBarWithNavController(navController, appBarConfiguration)*/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2022-06-10
    • 2018-04-03
    相关资源
    最近更新 更多