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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:16:10+00:00 2026-06-16T17:16:10+00:00

I attempted to create my ImageButton using a the initializeBtn() function but __animateBtn is

  • 0

I attempted to create my ImageButton using a the initializeBtn() function but __animateBtn is null when I checked it running the function. Any thoughts?

When I don’t attempt to catch the null __animateBtn, LogCat throw a null pointer exception.

public class MainActivity extends Activity implements OnTouchListener {

public static ImageButton __animateBtn;

public static myLayout __myLayout;  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    
    setContentView(R.layout.activity_main);

    if (__animateBtn == null) {
        initializeBtn (__animateBtn, R.drawable.wrapped_leavemenu_0, false);

    }

    if(__myLayout == null) {

        __myLayout = (myLayout) findViewById(R.id.relative_layout);

        if (__animateBtn == null) {
            Log.d("__animateBtn", "null");
            finish();
        }
        if (__animateBtn2 == null) {
            Log.d("__animateBtn2", "null");
            finish();
        }
        else {
        Log.d ("__myLayout.addView", "are" + __myLayout.getChildCount());               
        __myLayout.addView(__animateBtn, new AbsoluteLayout.LayoutParams(100,140,midX,midY-100));
        __myLayout.addView(__animateBtn2, new AbsoluteLayout.LayoutParams(200,100,midX-100,midY));
        }

    }   

public void initializeBtn (ImageButton btn, int resid, boolean visible) {

    btn = new ImageButton (getApplicationContext());
    btn.setBackgroundResource(resid);

    if (visible) btn.setVisibility(View.VISIBLE);
    else btn.setVisibility(View.INVISIBLE);
}
}
  • 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-16T17:16:11+00:00Added an answer on June 16, 2026 at 5:16 pm

    use :

    public ImageButton initializeBtn (int resid, boolean visible) {
    
        ImageButton btn = new ImageButton (this);// use this instead of getApplicationContext()
        btn.setBackgroundResource(resid);
    
        if (visible) btn.setVisibility(View.VISIBLE);
        else btn.setVisibility(View.INVISIBLE);
        return btn;
    }
    

    and then in your onCreate() method :

    __animateBtn = initializeBtn(R.drawable.wrapped_leavemenu_0, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found only one attempt to create such compiler - http://sourceforge.net/projects/xsltc/ . But this
I have attempted to create a function that will replace multiple regular expression values
I have attempted to create my own UITypeEditor but the EditValue method never gets
Using this previous question as a guide, I've attempted to create a ul navigation
Well I attempted to create labels next to each other but depending on the
I am attempted to create a new Sales Order in Netsuite using PHPtoolkip_v2010.php and
This is the first time I have attempted to create a .dll, that will
I'm after a simple stored procedure to drop tables. Here's my first attempt: CREATE
Continuing on my attempt to create a DateTime class , I am trying to
This is my first attempt to create a GUI in MATLAB. I haven't been

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.