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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:24:28+00:00 2026-05-30T14:24:28+00:00

I have one superclass in my android project that inherits from activity and implements

  • 0

I have one superclass in my android project that inherits from activity and implements all the necessary interfaces. I then have three different activities that inherit from this superclass. I initialize the variables in the superclass from all the subclasses once the activities are created. Superclass method:

protected void initiateVariables(Context c){
    dm = new DisplayMetrics();
    toasty = new Toast(c);
    customBuilder = new MyDialog.Builder(c);
    customDialog = new Dialog(c);
    customProgress = new MyProgressDialog(c);
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;
    screenHeight = dm.heightPixels;
}

From the subclasses I do:

protected void initiateVariables(Context c) {
    super.initiateVariables(c);
    bFavorite = (Button) findViewById(R.id.bFavorite);
    bSetting = (Button) findViewById(R.id.bSettings);
    bCompass = (Button) findViewById(R.id.bCompass);
    bDeparture = (Button) findViewById(R.id.bDeparture);
    bInfo = (Button) findViewById(R.id.bInfo);
    bBack = (Button) findViewById(R.id.bBack);
    bDeparture2 = (Button) findViewById(R.id.bForward);
    bAdd = (Button) findViewById(R.id.bAdd);
    tvHeader = (TextView) findViewById(R.id.tvHeaderText);
    flipp = (ViewFlipper) findViewById(R.id.viewFlipper);
    colorBackground = (RelativeLayout) findViewById(R.id.homeBackground);
    dbList = (ListView) findViewById(R.id.dbList); }

onCreate method in my subclasses:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    initiateVariables(this);
}

When I try to use any object that has been initialized in the superclass I get a nullpointerexception. Could anyone explain to me why this is?

  • 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-30T14:24:30+00:00Added an answer on May 30, 2026 at 2:24 pm

    I suggest you to add all 3 Activity constructors in the superclass and call initiateVariables(Context c) this method from all of them… May be you are missing it..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of classes that inherit from one superclass. The superclass as
I have created two viewController classes such that one is superclass of another.i have
I have one class called HyperlinkEventMonitor that implements a HyperlinkListener. I want to extend
Say I have one superclass, and several subclasses inheriting it. I'd like to cram
have one time consuming step that flattens a bunch of files. basically i'd like
I have one <asp:Image ID=imgBanner1 runat=server/> control in my aspx page, then in code
I want to have a function defined in a superclass that returns an instance
Think that I have many activities,and all I want is this: I have a
I have a listener class that accepts GUI change events in one method. The
I have two subclasess inheriting from the same abstract superclass. There is a common

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.