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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:14:07+00:00 2026-06-11T10:14:07+00:00

I am making an android app, where, during startup I disable the pauze button

  • 0

I am making an android app, where, during startup I disable the pauze button of the media player. After the ok button is clicked (and music starts to play), I want to enable the pauze button.

This code works fine, except for the last line (I did delete some non-relevant lines). That gives me a runtime error (NullPointerException).

I used MainActivity.this to access the button. What am I doing wrong?

Thank you for any help!

public class MainActivity extends Activity {

    // initialise variables
    TextView textOut;
    MediaPlayer mediaPlayer;
    Button buttonPauze;
    Button ok;

    // *******************************************************
    // set Layout - on create
    // *******************************************************
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textOut = (TextView) findViewById(R.id.textView1);


        // *******************************************************
        // set the play, generate and pauze buttons
        // *******************************************************
        Button buttonPauze = (Button) findViewById(R.id.buttonPauze);
        Button ok = (Button) findViewById(R.id.buttonStart);

        buttonPauze.setOnClickListener(buttonPauseOnClickListener);
    buttonPauze.setEnabled(false);
    ok.setEnabled(true);

    // *******************************************************
    // on click generate
    // *******************************************************
    ok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            MainActivity.this.buttonPauze.setEnabled(true);
  • 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-11T10:14:08+00:00Added an answer on June 11, 2026 at 10:14 am

    Replace:

    Button buttonPauze = (Button) findViewById(R.id.buttonPauze);
    

    with:

    buttonPauze = (Button) findViewById(R.id.buttonPauze);
    

    Basically, you had 2 buttonPauze‘s, one as local variable and the other as a class field. By removing the Button, you are using the class field buttonPauze locally and assign a proper object to it.


    Same thing with ok!

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

Sidebar

Related Questions

I'm making a dictionary app on android. During its startup, the app will load
I am making an android app for http://yearbook08.com/ I know how to parse through
I am making an android app. I have a main activity and i want
I'm making an android app, and I need to save the double value(BodySize) to
So I'm making an android app that has more than 100 buttons,but you know
I am making an android app in which i am trying to slide between
I'm making a Android app that basically plays video from a website on the
I am making an android app that uses a webview to visit a website.
So, I'm making an Android app, and I have thought of a strategy to
i am new to programming and hence android programming. I'm making an android app

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.