Hetal Patel
Hetal Patel

Reputation: 31

Android error java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitle

I am new to Android. It shows error during bottom navigation.

Error :

Android error java.lang.NullPointerException: Attempt to invoke virtual method '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);
    }

Upvotes: 2

Views: 1375

Answers (1)

dingpwen
dingpwen

Reputation: 161

If you want to show a no-titled screen, you first shoud remove the android:label in your navigation.xml:

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

and then in your activity, remove following codes:

// 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)*/

Upvotes: 3

Related Questions