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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:49:48+00:00 2026-06-05T13:49:48+00:00

I am working android application that required login, Now I want After successfully login

  • 0

I am working android application that required login, Now I want After successfully login into my application, login button should be invisible and logout button should be visible, but getting errors.

I am using this function:

login.setVisibility(View.GONE);    &    logout.setVisibility(View.VISIBLE);  

Eclipse give me error in logcat like:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rahul.cheerfoolz/com.rahul.cheerfoolz.CheerfoolznativeActivity}: java.lang.NullPointerException.

Main.class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

      session = new SessionID();
      Button login = (Button) findViewById(R.id.home_btn_feature_login);
      Button logout = (Button) findViewById(R.id.home_btn_feature_logout);

         int userID = SessionID.getUserID();

         System.out.println("value of the userID into the main page:====>"+userID);
         //  when user login then here I got the userID value

        if ((userID) > 0) {

            login.setVisibility(View.GONE);  //when Execute this give me error
            logout.setVisibility(View.VISIBLE);  //when Execute this give me error

        } else {

            login.setVisibility(View.VISIBLE); //when Execute this give me error
            logout.setVisibility(View.GONE); //when Execute this give me error

        }

    setContentView(R.layout.main);
    setHeader_home("");
    }

Main.xml

   <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:orientation="horizontal" >

   <!-- Here Login Button  -->

        <Button
            android:id="@+id/home_btn_feature_login"
            style="@style/HomeButton"
            android:drawableTop="@drawable/login_button"
            android:onClick="onClickFeature"
            android:text="@string/title_feature_login" />

   <!-- Here Logout Button  -->

        <Button
            android:id="@+id/home_btn_feature_logout"
            style="@style/HomeButton"
            android:drawableTop="@drawable/logout_button"
            android:onClick="onClickFeature"
            android:text="@string/title_feature_logout" />

        <Button
            android:id="@+id/home_btn_feature2"
            style="@style/HomeButton"
            android:drawableTop="@drawable/register_button"
            android:onClick="onClickFeature"
            android:text="@string/title_feature_register" />
    </LinearLayout>
  • 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-05T13:49:49+00:00Added an answer on June 5, 2026 at 1:49 pm

    You have to add setContentView(R.layout.main) after super.onCreate(savedInstanceState);
    or before Accessing Any View from XML Layout File.Then your Button get refrenced from xml.and in code can’t get Button refrence from main.xml .so NullPointer Exception.

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);<<<<<<<<<<<<<<ADD THIS LINE
    
    
        session = new SessionID();
        Button login = (Button) findViewById(R.id.home_btn_feature_login);
        Button logout = (Button) findViewById(R.id.home_btn_feature_logout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on the android application that required login. I want to check
I am working on an Android application that is required to connect to a
I am working on an Android application that requires a user to login before
I am working on an android application that determines user location in osm maps.
Hey I was working on an android application that sends and receives text messages,
I am working on a private android application that will involve the use of
When working on a localized Android application, I found it a bit annoying that
I am working on an android application which has to be translated into several
I am working on an Android application. I want to implement search functionality in
I am working on an android application that requires multiple views which will overlap

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.