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

  • Home
  • SEARCH
  • 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 6764843
In Process

The Archive Base Latest Questions

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

I keep getting NullPointerException trying to deflate or make invisible the ViewStub from my

  • 0

I keep getting NullPointerException trying to deflate or make invisible the ViewStub from my UI. I just wanted to be sure I am doing it right.

I am inflating my ViewStub in onItemLongClick method of GalleryView by doing the following:

@Override
            public boolean onItemLongClick(AdapterView<?> arg0, View viu, int arg2,
                    long arg3) {
                Toast.makeText(GalleryView.this, "New item added to Favorites", Toast.LENGTH_SHORT).show();


                favsCount++;

               //checking to see if ViewStub is already inflated or not
                if(!stubvis){
                stub = (ViewStub) findViewById(R.id.stub1);
                stub.inflate();
                stubvis = true;
                trayUP = true;
                }

                return true;
            }

            });

and then in onPrepareOptionsMenu() I am adding the menu item based on the visibility of ViewStub. If inflated and visible, I create a menu item to hide it, otherwise, a menu item to show/make visible.

@Override

public boolean onPrepareOptionsMenu(Menu menu) {

menu.clear();


if(trayUP) {

menu.add(0, HIDETRAY, 0, "Hide Favorites Tray");

} else {

menu.add(0, SHOWTRAY, 0, "Show Favorites Tray");

}

return super.onPrepareOptionsMenu(menu);

}

Next, in onOptionsItemSelected(), I am writing the two cases based on the menu item selection. Case 1 when the tray is not visible, so I make it visible. Case 2 when it is visible, so I hide it by doing the following:

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case HIDETRAY:

            Log.v(TAG, "Hiding Favs Tray");
            findViewById(R.id.stub1).setVisibility(View.GONE);
            trayUP = false;

        case SHOWTRAY:

            Log.v(TAG, "Showing Favs Tray");
            findViewById(R.id.stub1).setVisibility(View.VISIBLE);
            trayUP = true;

        }

    return true;

}

I know I am making a silly mistake somewhere. And my mind is too saturated to think straight at the moment. Need help 🙁

Thanks,

Ab

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

    Abhishek, it looks like you’re trying to implement some sort of drawer functionality. You might be able to get around all of this mess of setting views visibilities if you simply use the SlidingDrawer class instead.

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

Sidebar

Related Questions

I am trying to write program and keep getting a nullPointerException when I call
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting empty files generated from running $command = 'mysqldump --opt -h localhost
Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):
I've got a hibernate query I'm trying to get working but keep getting an
Keep getting The constructor SimpleCursorAdapter(MyProgram, int, Cursor, int) is undefined and am not sure
I keep getting a NullPointerException when I call the method I created, draw(), in
I keep getting Activity Monitor Job. java.lang.NullPointerException while working with Eclipse 3.6 Has anybody
I keep getting this error 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): java.lang.NullPointerException 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): at com.fttech.organizeit.meeting_list$meetingHolder.populateFrom(meeting_list.java:110)
im trying to kick off a Runnable classes run method however i keep getting

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.