how can solve my NullPointerException issue in my AndroidIs there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Is there a unique Android device ID?What is the difference between gravity and layout_gravity in Android?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Rename package in Android StudioWhere do I place the 'assets' folder in Android Studio?

Use cases for M-0 & C-0?

What is the difference between 1/3, 1/2, and full casters?

sfdx force:org:list --all doesn't show all scratch orgs

Why can't my huge trees be chopped down?

Why force the nose of 737 Max down in the first place?

Is there a reason why I should not use the HaveIBeenPwned API to warn users about exposed passwords?

What do you call a flexible diving platform?

Melee or Ranged attacks by Monsters, no distinction in modifiers?

Character is called by their first initial. How do I write it?

Seaborn style plot of pandas dataframe

How to avoid theft of intellectual property when trying to obtain a Ph.D?

Why is 'n' preferred over "n" for output streams?

How many oliphaunts died in all of the Lord of the Rings battles?

To find islands of 1 and 0 in matrix

How to kill my goat in Goat Simulator

How can religions be structured in ways that allow inter-faith councils to work?

Am I allowed to use personal conversation as a source?

How do I stop my characters falling in love?

How did the Axis intend to hold the Caucasus?

The Sword in the Stone

How to tar a list of directories only if they exist

Isolated audio without a transformer

Why is the number of local variables used in a Java bytecode method not the most economical?

Old French song lyrics with the word "baiser."



how can solve my NullPointerException issue in my Android


Is there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Is there a unique Android device ID?What is the difference between gravity and layout_gravity in Android?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Rename package in Android StudioWhere do I place the 'assets' folder in Android Studio?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have created android app using WebView



Functionality is working fine and But when i add private void createDialog() to showing alertdialog then whosing this error :




NullPointerException: Attempt to invoke virtual method 'void
android.app.Dialog.show()'




on a null object reference in Logcat



Here is my fragment code :



public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener

public Dialog mDialog;
public Button mDialogyes, mDialogno;

ProgressBar progressBar;
WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView=(WebView) findViewById(R.id.webView);

webView.setVisibility(View.INVISIBLE);
webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());

webView.setWebViewClient(new WebViewClient()
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
super.onPageStarted(view, url, favicon);
setProgressBarVisibility(View.VISIBLE);


@Override
public void onPageFinished(WebView view, String url)
super.onPageFinished(view, url);
setProgressBarVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);


@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
super.onReceivedError(view, request, error);
setProgressBarVisibility(View.GONE);

);
webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");


FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)



);

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.setItemIconTintList(null);
navigationView.setNavigationItemSelectedListener(this);

ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activenetnetwork = cm.getActiveNetworkInfo();
if(activenetnetwork != null)

if(activenetnetwork.getType() == ConnectivityManager.TYPE_WIFI)

//Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();
else if(activenetnetwork.getType() == ConnectivityManager.TYPE_MOBILE)

//Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();

else

ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Web page not available");
Toast.makeText(getApplicationContext(),"Please Check your Internet ",Toast.LENGTH_LONG).show();





private void setProgressBarVisibility(int visibility)
// If a user returns back, a NPE may occur if WebView is still loading a page and then tries to hide a ProgressBar.
if (progressBar != null)
progressBar.setVisibility(visibility);



private void createDialog()
mDialog = new Dialog(this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.dialog_exit);
mDialog.setCanceledOnTouchOutside(true);
mDialog.setCancelable(true);
mDialogyes = (Button) mDialog.findViewById(R.id.yes);
mDialogno = (Button) mDialog.findViewById(R.id.no);



mDialogyes.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
finish();
System.exit(0);




);

mDialogno.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
mDialog.dismiss();

);



@Override
public void onBackPressed()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else
mDialog.show();




@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;


@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
return true;


return super.onOptionsItemSelected(item);


@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.home)


else if (id == R.id.contact)

else if (id == R.id.about)

else if (id == R.id.share)

else if (id == R.id.rate)

else if (id == R.id.more)



DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;











share|improve this question






























    0















    I have created android app using WebView



    Functionality is working fine and But when i add private void createDialog() to showing alertdialog then whosing this error :




    NullPointerException: Attempt to invoke virtual method 'void
    android.app.Dialog.show()'




    on a null object reference in Logcat



    Here is my fragment code :



    public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener

    public Dialog mDialog;
    public Button mDialogyes, mDialogno;

    ProgressBar progressBar;
    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    webView=(WebView) findViewById(R.id.webView);

    webView.setVisibility(View.INVISIBLE);
    webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");
    WebSettings webSettings=webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(new WebViewClient()
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon)
    super.onPageStarted(view, url, favicon);
    setProgressBarVisibility(View.VISIBLE);


    @Override
    public void onPageFinished(WebView view, String url)
    super.onPageFinished(view, url);
    setProgressBarVisibility(View.GONE);
    webView.setVisibility(View.VISIBLE);


    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
    super.onReceivedError(view, request, error);
    setProgressBarVisibility(View.GONE);

    );
    webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener()
    @Override
    public void onClick(View view)



    );

    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.setItemIconTintList(null);
    navigationView.setNavigationItemSelectedListener(this);

    ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activenetnetwork = cm.getActiveNetworkInfo();
    if(activenetnetwork != null)

    if(activenetnetwork.getType() == ConnectivityManager.TYPE_WIFI)

    //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();
    else if(activenetnetwork.getType() == ConnectivityManager.TYPE_MOBILE)

    //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();

    else

    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("Web page not available");
    Toast.makeText(getApplicationContext(),"Please Check your Internet ",Toast.LENGTH_LONG).show();





    private void setProgressBarVisibility(int visibility)
    // If a user returns back, a NPE may occur if WebView is still loading a page and then tries to hide a ProgressBar.
    if (progressBar != null)
    progressBar.setVisibility(visibility);



    private void createDialog()
    mDialog = new Dialog(this);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setContentView(R.layout.dialog_exit);
    mDialog.setCanceledOnTouchOutside(true);
    mDialog.setCancelable(true);
    mDialogyes = (Button) mDialog.findViewById(R.id.yes);
    mDialogno = (Button) mDialog.findViewById(R.id.no);



    mDialogyes.setOnClickListener(new View.OnClickListener()
    @Override
    public void onClick(View v)
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
    finish();
    System.exit(0);




    );

    mDialogno.setOnClickListener(new View.OnClickListener()
    @Override
    public void onClick(View v)
    mDialog.dismiss();

    );



    @Override
    public void onBackPressed()
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START))
    drawer.closeDrawer(GravityCompat.START);
    else
    mDialog.show();




    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;


    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings)
    return true;


    return super.onOptionsItemSelected(item);


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item)
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.home)


    else if (id == R.id.contact)

    else if (id == R.id.about)

    else if (id == R.id.share)

    else if (id == R.id.rate)

    else if (id == R.id.more)



    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;











    share|improve this question


























      0












      0








      0








      I have created android app using WebView



      Functionality is working fine and But when i add private void createDialog() to showing alertdialog then whosing this error :




      NullPointerException: Attempt to invoke virtual method 'void
      android.app.Dialog.show()'




      on a null object reference in Logcat



      Here is my fragment code :



      public class MainActivity extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener

      public Dialog mDialog;
      public Button mDialogyes, mDialogno;

      ProgressBar progressBar;
      WebView webView;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);

      progressBar = (ProgressBar) findViewById(R.id.progressBar);
      webView=(WebView) findViewById(R.id.webView);

      webView.setVisibility(View.INVISIBLE);
      webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");
      WebSettings webSettings=webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webView.setWebChromeClient(new WebChromeClient());

      webView.setWebViewClient(new WebViewClient()
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon)
      super.onPageStarted(view, url, favicon);
      setProgressBarVisibility(View.VISIBLE);


      @Override
      public void onPageFinished(WebView view, String url)
      super.onPageFinished(view, url);
      setProgressBarVisibility(View.GONE);
      webView.setVisibility(View.VISIBLE);


      @Override
      public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
      super.onReceivedError(view, request, error);
      setProgressBarVisibility(View.GONE);

      );
      webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");


      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View view)



      );

      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.setItemIconTintList(null);
      navigationView.setNavigationItemSelectedListener(this);

      ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activenetnetwork = cm.getActiveNetworkInfo();
      if(activenetnetwork != null)

      if(activenetnetwork.getType() == ConnectivityManager.TYPE_WIFI)

      //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();
      else if(activenetnetwork.getType() == ConnectivityManager.TYPE_MOBILE)

      //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();

      else

      ActionBar actionBar = getSupportActionBar();
      actionBar.setTitle("Web page not available");
      Toast.makeText(getApplicationContext(),"Please Check your Internet ",Toast.LENGTH_LONG).show();





      private void setProgressBarVisibility(int visibility)
      // If a user returns back, a NPE may occur if WebView is still loading a page and then tries to hide a ProgressBar.
      if (progressBar != null)
      progressBar.setVisibility(visibility);



      private void createDialog()
      mDialog = new Dialog(this);
      mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
      mDialog.setContentView(R.layout.dialog_exit);
      mDialog.setCanceledOnTouchOutside(true);
      mDialog.setCancelable(true);
      mDialogyes = (Button) mDialog.findViewById(R.id.yes);
      mDialogno = (Button) mDialog.findViewById(R.id.no);



      mDialogyes.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View v)
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
      intent.addCategory(Intent.CATEGORY_HOME);
      startActivity(intent);
      finish();
      System.exit(0);




      );

      mDialogno.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View v)
      mDialog.dismiss();

      );



      @Override
      public void onBackPressed()
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(GravityCompat.START))
      drawer.closeDrawer(GravityCompat.START);
      else
      mDialog.show();




      @Override
      public boolean onCreateOptionsMenu(Menu menu)
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;


      @Override
      public boolean onOptionsItemSelected(MenuItem item)
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();

      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings)
      return true;


      return super.onOptionsItemSelected(item);


      @SuppressWarnings("StatementWithEmptyBody")
      @Override
      public boolean onNavigationItemSelected(MenuItem item)
      // Handle navigation view item clicks here.
      int id = item.getItemId();

      if (id == R.id.home)


      else if (id == R.id.contact)

      else if (id == R.id.about)

      else if (id == R.id.share)

      else if (id == R.id.rate)

      else if (id == R.id.more)



      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
      return true;











      share|improve this question
















      I have created android app using WebView



      Functionality is working fine and But when i add private void createDialog() to showing alertdialog then whosing this error :




      NullPointerException: Attempt to invoke virtual method 'void
      android.app.Dialog.show()'




      on a null object reference in Logcat



      Here is my fragment code :



      public class MainActivity extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener

      public Dialog mDialog;
      public Button mDialogyes, mDialogno;

      ProgressBar progressBar;
      WebView webView;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);

      progressBar = (ProgressBar) findViewById(R.id.progressBar);
      webView=(WebView) findViewById(R.id.webView);

      webView.setVisibility(View.INVISIBLE);
      webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");
      WebSettings webSettings=webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webView.setWebChromeClient(new WebChromeClient());

      webView.setWebViewClient(new WebViewClient()
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon)
      super.onPageStarted(view, url, favicon);
      setProgressBarVisibility(View.VISIBLE);


      @Override
      public void onPageFinished(WebView view, String url)
      super.onPageFinished(view, url);
      setProgressBarVisibility(View.GONE);
      webView.setVisibility(View.VISIBLE);


      @Override
      public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
      super.onReceivedError(view, request, error);
      setProgressBarVisibility(View.GONE);

      );
      webView.loadUrl("http://m.jazz.com.pk/smart/wifi_3g.html");


      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View view)



      );

      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.setItemIconTintList(null);
      navigationView.setNavigationItemSelectedListener(this);

      ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activenetnetwork = cm.getActiveNetworkInfo();
      if(activenetnetwork != null)

      if(activenetnetwork.getType() == ConnectivityManager.TYPE_WIFI)

      //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();
      else if(activenetnetwork.getType() == ConnectivityManager.TYPE_MOBILE)

      //Toast.makeText(getApplicationContext(),activenetnetwork.getTypeName(),Toast.LENGTH_LONG).show();

      else

      ActionBar actionBar = getSupportActionBar();
      actionBar.setTitle("Web page not available");
      Toast.makeText(getApplicationContext(),"Please Check your Internet ",Toast.LENGTH_LONG).show();





      private void setProgressBarVisibility(int visibility)
      // If a user returns back, a NPE may occur if WebView is still loading a page and then tries to hide a ProgressBar.
      if (progressBar != null)
      progressBar.setVisibility(visibility);



      private void createDialog()
      mDialog = new Dialog(this);
      mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
      mDialog.setContentView(R.layout.dialog_exit);
      mDialog.setCanceledOnTouchOutside(true);
      mDialog.setCancelable(true);
      mDialogyes = (Button) mDialog.findViewById(R.id.yes);
      mDialogno = (Button) mDialog.findViewById(R.id.no);



      mDialogyes.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View v)
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
      intent.addCategory(Intent.CATEGORY_HOME);
      startActivity(intent);
      finish();
      System.exit(0);




      );

      mDialogno.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View v)
      mDialog.dismiss();

      );



      @Override
      public void onBackPressed()
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(GravityCompat.START))
      drawer.closeDrawer(GravityCompat.START);
      else
      mDialog.show();




      @Override
      public boolean onCreateOptionsMenu(Menu menu)
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;


      @Override
      public boolean onOptionsItemSelected(MenuItem item)
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();

      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings)
      return true;


      return super.onOptionsItemSelected(item);


      @SuppressWarnings("StatementWithEmptyBody")
      @Override
      public boolean onNavigationItemSelected(MenuItem item)
      // Handle navigation view item clicks here.
      int id = item.getItemId();

      if (id == R.id.home)


      else if (id == R.id.contact)

      else if (id == R.id.about)

      else if (id == R.id.share)

      else if (id == R.id.rate)

      else if (id == R.id.more)



      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
      return true;








      android android-layout android-studio dialog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 18:48









      ankuranurag2

      1,2995 silver badges19 bronze badges




      1,2995 silver badges19 bronze badges










      asked Aug 6 '18 at 19:34









      Ayan AppsAyan Apps

      185 bronze badges




      185 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Looking at your code, the method createDialog() is never called, so the value of mDialog is always null. You need to initialize the dialog (i.e. by calling createDialog()) before you can call mDialog.show(); in your onBackPressed() override.






          share|improve this answer























          • same code working in my other application

            – Ayan Apps
            Aug 6 '18 at 19:40











          • i missed createDialog(); its working now Thanks

            – Ayan Apps
            Aug 6 '18 at 20:01


















          0














          Need a null pointer check before calling the show method. Example:



          if (mDialog != null) 
          mDialog.show();



          As commented above, your mDialog is null because you need to call the createDialog method first. Whatever code you copied from another application missed something.






          share|improve this answer























          • yeah you are right i missed createDialog();

            – Ayan Apps
            Aug 6 '18 at 19:59













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51714527%2fhow-can-solve-my-nullpointerexception-issue-in-my-android%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Looking at your code, the method createDialog() is never called, so the value of mDialog is always null. You need to initialize the dialog (i.e. by calling createDialog()) before you can call mDialog.show(); in your onBackPressed() override.






          share|improve this answer























          • same code working in my other application

            – Ayan Apps
            Aug 6 '18 at 19:40











          • i missed createDialog(); its working now Thanks

            – Ayan Apps
            Aug 6 '18 at 20:01















          2














          Looking at your code, the method createDialog() is never called, so the value of mDialog is always null. You need to initialize the dialog (i.e. by calling createDialog()) before you can call mDialog.show(); in your onBackPressed() override.






          share|improve this answer























          • same code working in my other application

            – Ayan Apps
            Aug 6 '18 at 19:40











          • i missed createDialog(); its working now Thanks

            – Ayan Apps
            Aug 6 '18 at 20:01













          2












          2








          2







          Looking at your code, the method createDialog() is never called, so the value of mDialog is always null. You need to initialize the dialog (i.e. by calling createDialog()) before you can call mDialog.show(); in your onBackPressed() override.






          share|improve this answer













          Looking at your code, the method createDialog() is never called, so the value of mDialog is always null. You need to initialize the dialog (i.e. by calling createDialog()) before you can call mDialog.show(); in your onBackPressed() override.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 6 '18 at 19:36









          Eric BachhuberEric Bachhuber

          1,1601 gold badge9 silver badges19 bronze badges




          1,1601 gold badge9 silver badges19 bronze badges












          • same code working in my other application

            – Ayan Apps
            Aug 6 '18 at 19:40











          • i missed createDialog(); its working now Thanks

            – Ayan Apps
            Aug 6 '18 at 20:01

















          • same code working in my other application

            – Ayan Apps
            Aug 6 '18 at 19:40











          • i missed createDialog(); its working now Thanks

            – Ayan Apps
            Aug 6 '18 at 20:01
















          same code working in my other application

          – Ayan Apps
          Aug 6 '18 at 19:40





          same code working in my other application

          – Ayan Apps
          Aug 6 '18 at 19:40













          i missed createDialog(); its working now Thanks

          – Ayan Apps
          Aug 6 '18 at 20:01





          i missed createDialog(); its working now Thanks

          – Ayan Apps
          Aug 6 '18 at 20:01













          0














          Need a null pointer check before calling the show method. Example:



          if (mDialog != null) 
          mDialog.show();



          As commented above, your mDialog is null because you need to call the createDialog method first. Whatever code you copied from another application missed something.






          share|improve this answer























          • yeah you are right i missed createDialog();

            – Ayan Apps
            Aug 6 '18 at 19:59















          0














          Need a null pointer check before calling the show method. Example:



          if (mDialog != null) 
          mDialog.show();



          As commented above, your mDialog is null because you need to call the createDialog method first. Whatever code you copied from another application missed something.






          share|improve this answer























          • yeah you are right i missed createDialog();

            – Ayan Apps
            Aug 6 '18 at 19:59













          0












          0








          0







          Need a null pointer check before calling the show method. Example:



          if (mDialog != null) 
          mDialog.show();



          As commented above, your mDialog is null because you need to call the createDialog method first. Whatever code you copied from another application missed something.






          share|improve this answer













          Need a null pointer check before calling the show method. Example:



          if (mDialog != null) 
          mDialog.show();



          As commented above, your mDialog is null because you need to call the createDialog method first. Whatever code you copied from another application missed something.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 6 '18 at 19:49









          CodeSmithCodeSmith

          1,0951 gold badge9 silver badges24 bronze badges




          1,0951 gold badge9 silver badges24 bronze badges












          • yeah you are right i missed createDialog();

            – Ayan Apps
            Aug 6 '18 at 19:59

















          • yeah you are right i missed createDialog();

            – Ayan Apps
            Aug 6 '18 at 19:59
















          yeah you are right i missed createDialog();

          – Ayan Apps
          Aug 6 '18 at 19:59





          yeah you are right i missed createDialog();

          – Ayan Apps
          Aug 6 '18 at 19:59

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51714527%2fhow-can-solve-my-nullpointerexception-issue-in-my-android%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript