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 6685381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:03:05+00:00 2026-05-26T05:03:05+00:00

I am developing an Android app, this app has a dozen of Activities, each

  • 0

I am developing an Android app, this app has a dozen of Activities, each one is for a corresponding screen. Now I have this common subtitle bar on top of the screens.
this subtitle bar has a button to display an alert dialog which shows link list to go to a different screen.

I could write a same function for each activity to call the alert dialog, but that would be tedious if I want to modify them, so I created this class:

public class MenuAlertDialog extends Activity {

/*
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}
 */
public void createMenu(final Context context){
    AlertDialog.Builder dlg = new AlertDialog.Builder(context);
    dlg.setTitle("menu");

    String[] items = {"pageA", "pageB", "pageC", "pageD", "pageE"};
    dlg.setItems(items, new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which){
            switch(which){
            case 0:
                Intent intent = new Intent(context, MainActivity.class);
                startActivity(intent);
                break;
            default:
                break;

            }
        }
    });
    dlg.show();
}
}

and call it from each activity, like this:

MenuAlertDialog menu = new MenuAlertDialog();
menu.createMenu(this);

from inside of onCreate.

It can display the alertDialog, but whenever I press pageA link, it fails with an unexpected error.

Logcat says its a nullpointererror and the cause seems

startActivity(intent);

What am I doing wrong?

  • 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-05-26T05:03:05+00:00Added an answer on May 26, 2026 at 5:03 am

    Remove the code

    extends Activity
    

    as you have no need to extend your class that you are creating since it does not rely on any activity related functionality.

    Where you call startActivity(intent); replace it with

    context.startActivity(intent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an android app that has a bunch of screens (activities) that are
I'm developing an android app, and have developed a game, but I now have
I am developing an android app which has Facebook integration in it. I have
I am developing an android app which has a button in one activity and
I'm developing an Android project which currently has 4 packages: com.myapp.app.activities com.myapp.app.db com.myapp.app.ws com.myapp.app.utils
i am developing an android todo list app to learn. right now in my
I have been developing an Android app and testing with a 1.5 AVD and
Has anyone had success developing a substantial Android app in Scala? Is it a
I'm developing an iPhone (and later Android) app that has real-time features, i.e. when
I'm developing a webapp+android app that has its own registration flow - simple authentication

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.