My app crashed when clicking new dependency question. I don't know what is the error and how to solved it [duplicate]

96
April 20, 2022, at 10:40 PM
This question already has answers here:
What is a NullPointerException, and how do I fix it? (12 answers)
Closed 2 months ago.

Error E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.login, PID: 6969 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.login/com.example.login.NavigationDrawer}: android.view.InflateException: Binary XML file line #15: Binary XML file line #19: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #19: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.google.android.material.navigation.NavigationView.getHeaderView(int)' on a null object reference at com.example.login.ui.questionnaire.QuestionnaireFragment.onCreateView(QuestionnaireFragment.java:80) at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841) at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2777) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3020) at androidx.fragment.app.FragmentStateManager.ensureInflatedView(FragmentStateManager.java:394) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:260) at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:142) at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135) at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:295) at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:274) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) at android.view.LayoutInflater.rInflate(LayoutInflater.java:867) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:999) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:999) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828) at android.view.LayoutInflater.inflate(LayoutInflater.java:519) at android.view.LayoutInflater.inflate(LayoutInflater.java:427) at com.example.login.databinding.ActivityNavigationDrawerBinding.inflate(ActivityNavigationDrawerBinding.java:54) at com.example.login.databinding.ActivityNavigationDrawerBinding.inflate(ActivityNavigationDrawerBinding.java:48) E/AndroidRuntime: at com.example.login.NavigationDrawer.onCreate(NavigationDrawer.java:42) at android.app.Activity.performCreate(Activity.java:7224) at android.app.Activity.performCreate(Activity.java:7213) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873

Java Code
package com.example.login;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.login.databinding.ActivityNavigationDrawerBinding;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
public class NavigationDrawer extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
private ActivityNavigationDrawerBinding binding;
private String username;
private EditText etUsername;
Pref pref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pref = new Pref(getApplicationContext());
//get username from login page
username = pref.getUsername();
//System.out.println("username in 2nd  "+username);
binding = ActivityNavigationDrawerBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
//setContentView(binding.navView);
setSupportActionBar(binding.appBarNavigationDrawer.toolbar);
binding.appBarNavigationDrawer.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = binding.drawerLayout;
NavigationView navigationView = binding.navView;
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_questionnaire, R.id.nav_submitsurvey, R.id.nav_responses, R.id.nav_imagecapture, R.id.nav_dashboard)
.setOpenableLayout(drawer)
.build();
 NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_navigation_drawer);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.navigation_drawer, menu);
//display welcome username
etUsername = findViewById(R.id.welcomeUsername);
 etUsername.setText(username);
 Button button_log_out = findViewById(R.id.button_log_out);
button_log_out.setOnClickListener(new View.OnClickListener() {
 @Override
public void onClick(View v) {
logoutDialog();
}
});
return true;
    }
    @Override
    public boolean onSupportNavigateUp() {
 NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_navigation_drawer);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
 || super.onSupportNavigateUp();
}
public void logoutDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("LogOut Alert!");
alertDialog.setMessage("Are you sure want to LogOut this Application?");
alertDialog.setCancelable(true);
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
  pref.setLogin("no");
dialog.dismiss();
Intent intent = new Intent(NavigationDrawer.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
 @Override
 public void onClick(DialogInterface dialog, int which) {
 dialog.dismiss();
 }
        });
alertDialog.show();
    }
}
Answer 1

you have a NullPointerException. You should check whether the data you receive is full. For example if(data != null){ . . . ... }

Rent Charter Buses Company
READ ALSO
Material Container Transform animation not working in Java

Material Container Transform animation not working in Java

Im trying to use Material Container Transform in Recyclerview Adapter as described by this post MaterialContainerTransform transition is not Working on Return , but after implementing this in my project im getting null pointer exception errorAs everyone...

76
Store Image in Room Database using typeconverter to convert bitmap into bytearray. What to write in last parameter of the model class

Store Image in Room Database using typeconverter to convert bitmap into bytearray. What to write in last parameter of the model class

I don't know how to pass the bitmap as byteArray in the code belowI have added the parameter in the note model class and it is of type byte array

118
google reset new key certificate for me but certificate not working

google reset new key certificate for me but certificate not working

i am reset my certificate APK google play console

81
How to update and delete firebase data in android java?

How to update and delete firebase data in android java?

I am getting nothing in response while updating or deleting the data this line but the inserting and retriving works fine and please do answer i am new to android development

112