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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:32:19+00:00 2026-06-14T17:32:19+00:00

Why does this app I made crash when I run it on my phone

  • 0

Why does this app I made crash when I run it on my phone but it works perfectly fine on my tablet? When I run it on my phone get a java.NullPointerException at class.java:117
here is my entire activity.

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class Basketball extends Activity {

    int homecount, awaycount, minutes, seconds, sec, min;
        TextView home, away, timeEx;
    Button stop, start, reset, addhome, subhome, addaway, subaway, home2,
        home3, away2, away3;

    jakes.apps.scoreboard.CountDownTimer time;
    public boolean running;
    public int msElapsed;
    TextView time2;
    long startTime, stopTime;
    Button button;
    long timeWhenStopped; 
    int buttonCount, period;
    int ending;
    MediaPlayer ourSong;
    SharedPreferences getPrefs;
    getSystemService(Context.VIBRATOR_SERVICE);
    RadioButton first, second, third, fourth;

private void change() {
    // TODO Auto-generated method stub
    if ((buttonCount % 2) == 0) {
        start.setText("Start");
        stop.setText("Stop");
    } else {
        start.setText("Resume");
        stop.setText("Reset");
    }
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basketball);

    initize();

    time = new jakes.apps.scoreboard.CountDownTimer(900000, 1000) {

        public void onTick(long millisUntilFinished) {
            sec--;
            if (sec == 0) {
                min--;
                sec = 59;
            }
            if (sec < 10) {
                time2.setText(min + ":0" + sec);
            }
            time2.setText(min + ":" + sec);
        }

        public void onFinish() {
            if (period == 1) {
                Toast.makeText(getApplicationContext(),
                        "First period over", Toast.LENGTH_LONG).show();
                fourth.setChecked(false);
                third.setChecked(false);
                second.setChecked(true);
                first.setChecked(false);
                period++;

            } else if (period == 2) {
                Toast.makeText(getApplicationContext(),
                        "First period over", Toast.LENGTH_LONG).show();
                fourth.setChecked(false);
                third.setChecked(true);
                second.setChecked(false);
                first.setChecked(false);
                period++;

            } else if (period == 3) {
                Toast.makeText(getApplicationContext(),
                        "First period over", Toast.LENGTH_LONG).show();
                fourth.setChecked(true);
                third.setChecked(false);
                second.setChecked(false);
                first.setChecked(false);
                period++;

            } else if (period == 4) {
                gameover();

        }
    };

    addhome.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            homecount++;
            home.setText(homecount + "");
            boolean music = getPrefs.getBoolean("mute", false);
            if (music == false) {
                ourSong.start();
            }

        }
    });
    home2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            homecount = homecount + 2;
            home.setText(homecount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
            }

        }

    });
    home3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            homecount = homecount + 3;
            home.setText(homecount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
            }

        }
    });

    subhome.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            homecount--;
            home.setText(homecount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
            }

        }
    });
    addaway.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            awaycount++;
            away.setText(awaycount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        }
    });
    away2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            awaycount = awaycount + 2;
            away.setText(awaycount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        }
    });
    away3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            awaycount = awaycount + 3;
            away.setText(awaycount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        }
    });

    subaway.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            awaycount--;
            away.setText(awaycount + "");
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        }
    });

}

protected void gameover() {
    time2.setText("15:00");
    period = 0;
    fourth.setChecked(false);
    third.setChecked(false);
    second.setChecked(false);
    first.setChecked(true);
    if (homecount < awaycount) {
        Toast.makeText(getApplicationContext(), "Away team wins!!!",
                Toast.LENGTH_LONG).show();
    } else if (homecount > awaycount) {
        Toast.makeText(getApplicationContext(), "Home team wins!!!",
                Toast.LENGTH_LONG).show();
    } else if (homecount == awaycount) {
        Toast.makeText(getApplicationContext(), "Its a tie",
                Toast.LENGTH_LONG).show();
    }

}

private void initize() {
    // TODO Auto-generated method stub
    time2 = (TextView) findViewById(R.id.timer);
    start = (Button) findViewById(R.id.bStart);
    stop = (Button) findViewById(R.id.bStop);
    home3 = (Button) findViewById(R.id.add3home);
    home2 = (Button) findViewById(R.id.add2home);
    away3 = (Button) findViewById(R.id.add3away);
    away2 = (Button) findViewById(R.id.add2away);
    addhome = (Button) findViewById(R.id.bAddHome);
    addaway = (Button) findViewById(R.id.bAddAway);
    subhome = (Button) findViewById(R.id.bSubHome);
    subaway = (Button) findViewById(R.id.bSubAway);
    home = (TextView) findViewById(R.id.home);
    away = (TextView) findViewById(R.id.away);
    running = false;
    stopTime = 0;
    stopTime = 0;
    timeWhenStopped = 0;
    buttonCount = 1;

    button = (Button) findViewById(R.id.bStart);
    button.setOnClickListener(mStartListener);

    button = (Button) findViewById(R.id.bStop);
    button.setOnClickListener(mStopListener);

    ourSong = MediaPlayer.create(Basketball.this, R.raw.click);
    getPrefs = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext());
    min = 14;
    sec = 60;
    period = 1;

    first = (RadioButton) findViewById(R.id.first);
    second = (RadioButton) findViewById(R.id.second);
    third = (RadioButton) findViewById(R.id.third);
    fourth = (RadioButton) findViewById(R.id.fourth);
}

View.OnClickListener mStartListener = new OnClickListener() {
    public void onClick(View v) {
        start();
    }

};

View.OnClickListener mStopListener = new OnClickListener() {
    public void onClick(View v) {
        stop();

    }

};

private void stop() {
    // TODO Auto-generated method stub
    running = false;
    buttonCount++;
    change();
    time.pause();

    if ((buttonCount % 2) == 0) {
        reset();
    } else {

    }
    boolean music = getPrefs.getBoolean("mute", true);
    if (music == false) {
        ourSong.start();
        ourSong.release();
    }
}

protected void start() {
    if (running == true) {

    } else {
        if (((buttonCount % 2) == 0)) {
            time.resume();
            running = true;
            buttonCount++;
            change();
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        } else {

            buttonCount++;
            time.start();
            running = true;
            change();
            boolean music = getPrefs.getBoolean("mute", true);
            if (music == false) {
                ourSong.start();
                ourSong.release();
            }
        }
    }

}

private void reset() {
    // TODO Auto-generated method stub
    time.cancel();
    boolean music = getPrefs.getBoolean("mute", true);
    if (music == false) {
        ourSong.start();
        ourSong.release();
    }
    buttonCount++;
    sec = 1;
    time2.setText("15:00");
    min = 15;
}

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp = getMenuInflater();
    blowUp.inflate(R.menu.main, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.newgame:
        Intent NewGame = new Intent("jakes.apps.scoreboard.NEWGAME");
        startActivity(NewGame);
        break;
    case R.id.aboutus:
        Intent AboutUs = new Intent("jakes.apps.scoreboard.ABOUTUS");
        startActivity(AboutUs);
    case R.id.settings:

        Intent settings = new Intent("jakes.apps.scoreboard.SETTINGS");
        startActivity(settings);
        break;

    }
    return 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-14T17:32:20+00:00Added an answer on June 14, 2026 at 5:32 pm

    The value of the home2 variable is null when home2.setOnClickListener(... is executed.

    We cannot tell you why that is … or how to fix it … without more context.


    You say:

    home2 = (Button) findViewById(R.id.add2home); is run before it gets to this line

    There are five possible explanations:

    • The findViewById(R.id.add2home) call is returning null.

    • Something is changing home2 after the findViewById call.

    • You are mistaken, and that statement is NOT executed BEFORE the use of home2.

    • You have misinterpreted the original stacktrace and the NullPointerException is not thrown by that statement.

    • The code that you are actually executing is out of sync with the source code that you showed us … so that that exception is actually coming from somewhere else entirely.


    UPDATE – based on the complete code you have now posted, it seems like my first explanation is the correct one. And @spanjeta’s comment is very pertinent:

    Can you please post the layout xml file. Do you have multiple layouts in your code. I think button id is incorrect in xml layout and that’s why home2 is null.

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

Sidebar

Related Questions

If a run-time error occur in a VB6 app, does this mean Error handling
What does this mean? * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*
Google App Engine doesn't support SSL for custom domains. Does this mean that it's
I am setting up embedded forms in my rails app. This does not work
In this example from the App Engine docs , why does the example declare
This is a continuation of the question here: JBoss - does app have to
What does that mean? Getting this in the console during usage of my app
I'm working on an app for which I've made a release build to run
I've an app in the market with a few crash reports of java.lang.RuntimeException: native
I have made a small swing application for my personal use. This app connects

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.