Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:29:49+00:00 2026-06-02T05:29:49+00:00

After selecting a menu item , I am trying to show a custom dialog,

  • 0

After selecting a menu item , I am trying to show a custom dialog, however when I set the the onClickListener (works fine without onClickListner), a nullpointer error is shown. I check for button id typos and everything is correct.

Any Ideas as to why?

  public void  unlinkDeviceClick(MenuItem item){

   final Dialog alertDiag = new Dialog(Home.this); 
   alertDiag.setContentView(R.layout.unlinkdialog);
   alertDiag.setTitle("Unlink Device"); 

   Button yes = (Button)findViewById(R.id.signout);
   Button cancel = (Button)findViewById(R.id.cancelsignout);


   final EditText usernameField = (EditText)findViewById(R.id.usernameField);
   final EditText passwordField = (EditText)findViewById(R.id.passwordField);   
   final TextView descr = (TextView)findViewById(R.id.unlinkresults);    


   yes.setOnClickListener(new OnClickListener(){

       public void onClick(View v) {
        // TODO Auto-generated method stub
        String userName = usernameField.getText().toString();
        String password = passwordField.getText().toString();

        if(checkLoginFields(userName,password)){        
            if(checkCredentials(userName,password)){
                //loadUnlink(); 
                descr.setText("Sucessfully unlinked");
            }
            else{
                showWrongInfo(new View(Home.this));
            }
        }
        else{

        }

       }

   });


   cancel.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
        // TODO Auto-generated method stub
            alertDiag.dismiss();
        }

   });


   alertDiag.show();
}

//////////////////////Stack trace//////////////////////////////////////

    04-19 10:30:32.198: E/AndroidRuntime(20386): FATAL EXCEPTION: main
04-19 10:30:32.198: E/AndroidRuntime(20386): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.MenuInflater$InflatedOnMenuItemClickListener.onMenuItemClick(MenuInflater.java:203)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:154)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:964)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.view.menu.MenuBuilder$ActionMenuAdapter$1.onClick(MenuBuilder.java:1565)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.View.performClick(View.java:3135)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.View.onKeyUp(View.java:5055)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.KeyEvent.dispatch(KeyEvent.java:2623)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.View.dispatchKeyEvent(View.java:4603)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1157)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.widget.ListView.dispatchKeyEvent(ListView.java:2061)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1159)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.policy.impl.tv.TvWindow$DecorView.superDispatchKeyEvent(TvWindow.java:1161)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.policy.impl.tv.TvWindow.superDispatchKeyEvent(TvWindow.java:803)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.app.Dialog.dispatchKeyEvent(Dialog.java:706)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.policy.impl.tv.TvWindow$DecorView.dispatchKeyEvent(TvWindow.java:1117)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewRoot.deliverKeyEventPostIme(ViewRoot.java:2902)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2860)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.ViewRoot.handleMessage(ViewRoot.java:2059)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.os.Looper.loop(Looper.java:132)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.app.ActivityThread.main(ActivityThread.java:4083)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at java.lang.reflect.Method.invokeNative(Native Method)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at java.lang.reflect.Method.invoke(Method.java:491)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at dalvik.system.NativeStart.main(Native Method)
04-19 10:30:32.198: E/AndroidRuntime(20386): Caused by: java.lang.reflect.InvocationTargetException
04-19 10:30:32.198: E/AndroidRuntime(20386):    at java.lang.reflect.Method.invokeNative(Native Method)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at java.lang.reflect.Method.invoke(Method.java:491)
04-19 10:30:32.198: E/AndroidRuntime(20386):    at android.view.MenuInflater$InflatedOnMenuItemClickListener.onMenuItemClick(MenuInflater.java:199)
04-19 10:30:32.198: E/AndroidRuntime(20386):    ... 30 more
04-19 10:30:32.198: E/AndroidRuntime(20386): Caused by: java.lang.NullPointerException
04-19 10:30:32.198: E/AndroidRuntime(20386):    at com.ameba.api.activityClasses.Home.unlinkDeviceClick(Home.java:604)
04-19 10:30:32.198: E/AndroidRuntime(20386):    ... 33 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:29:50+00:00Added an answer on June 2, 2026 at 5:29 am

    If the buttons yes and cancel are in the dialog you’ll want to search for them in the dialog layout that you set:

    Button yes = (Button) alertDialog.findViewById(R.id.signout);
    Button cancel = (Button) alertDialog.findViewById(R.id.cancelsignout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to leave code completion menu without selecting any option? (after
I'm trying to present a modal view controller after selecting a contact and it
After selecting ListBox item programmatically it is needed to press down\up key two times
I have a list in a select. After selecting an option i do a
I have following requirement in my application. A tableView with games title After selecting
My dropDownList dropDown displayObject is stays visible after I am selecting an option. This
I am having trouble selecting an item from a Javascript dropdown (i.e. the items
I am trying to append a copy of a select menu to the bottom
I've handled screen rotation config changes in the android manifest, which works for dialog
I'd like to have a Word 2007+ AddIn (in C#) which after selecting text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.