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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:15:41+00:00 2026-06-11T13:15:41+00:00

I cannot figure out why but I keep getting E/AndroidRuntime(709): java.lang.NullPointerException at any point

  • 0

I cannot figure out why but I keep getting E/AndroidRuntime(709): java.lang.NullPointerException at any point I try to call the buttons titled yes and no. The buttons are created in an xml layout and called using the findViewById method, a similar technique I’ve used in several properly working buttons in the same program. The only difference between these buttons and the rest is that their xml code is kept in a separate layout file that is not the main.xml.

If I only want to show the buttons and don’t call them within the java code they will show up just as they should. The error occurs when I try to apply anything to them in the java code, such as setClickable() and setOnClickListener().

The code below outlines the creation of the button and layout in the xml and the java code shows a method that creates a popup when called.

Java Code:

    private void getLogoutOption() {
        LayoutInflater layoutInflater  = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        View popupView = layoutInflater.inflate(R.layout.logoutoption, null);  
        final PopupWindow logoutoption = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        Button yes = (Button) findViewById (R.id.yes);
        yes.setClickable(true);
        yes.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                logoutoption.dismiss();
                switchActivity(8);
            }
        });

        Button no = (Button) findViewById (R.id.no);
        no.setClickable(true);
        no.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                logoutoption.dismiss();
            }
        });

    logoutoption.showAsDropDown(search, 50, -30);
}

XML CODE:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent" >"

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/menu_default" >

        <TextView
            android:id="@+id/logoutmessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Are you sure you would like to logout?"
            android:textColor="@color/gold" />

        <Button
            android:id="@+id/yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/logoutmessage"
            android:layout_centerInParent="true"
            android:text="YES"
            android:textColor="@color/green" />

        <Button
            android:id="@+id/no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/logoutmessage"
            android:layout_toRightOf="@id/yes"
            android:text="NO"
            android:textColor="@color/red" />
    </RelativeLayout>

</RelativeLayout>
  • 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-11T13:15:42+00:00Added an answer on June 11, 2026 at 1:15 pm

    Change:

    Button yes = (Button) findViewById (R.id.yes);
    Button no = (Button) findViewById (R.id.no);
    

    To:

    Button yes = (Button) popupView.findViewById (R.id.yes);
    Button no = (Button) popupView.findViewById (R.id.no);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nearly tried everything but cannot figure out what is wrong. I have
I believe I seen it but cannot figure out where. Say I have the
I'm probably missing something very basic but I cannot figure out why I get
The bootstrap based maven-fluido-skin skin is eye candy but I cannot figure out how
I'm quite new to this, but i cannot figure out the problem. In twitter
It's a pretty basic question on matplotlib, but I cannot figure out how to
I am trying to fill object[] with List<string> but I cannot figure out how
I just cannot figure this out, it looks really simple but I'm relatively new
This is a bit of a trivial error but I cannot figure it out.
I started using NHibernate today, but I cannot figure out how I setup a

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.