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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:31:32+00:00 2026-06-10T01:31:32+00:00

I have been following some android tutorials on the web. I tried copying his

  • 0

I have been following some android tutorials on the web. I tried copying his code to the best of my ability but whenever I run the application it crashes. I looked through the console and found it was a Nullpointer exception that caused it. The application is meant to play a sound and then close and then go to another layout.
Here is my code, please tell me what I did wrong.

    package com.greg.hello;

    import android.app.Activity;
    import android.content.Intent;
    import android.media.MediaPlayer;
    import android.os.Bundle;

    public class MainActivity extends Activity {
    MediaPlayer mpSplash;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.explosion);
        mpSplash.start();
        Thread logoTimer = new Thread(){
            public void run(){
                try{
                    int logoTimer=0;
                    while(logoTimer<8000){
                        sleep(100);
                        logoTimer=logoTimer+100;
                    }
                    startActivity(new     Intent("com.greg.hello.CLEARSCREEN"));
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    setContentView(R.layout.tutorial1);
                    e.printStackTrace();
                }

                finally{
                    finish();
                }
            }   
        };
        logoTimer.start();
        finish();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        mpSplash.release();
        startActivity(new Intent("com.greg.hello.TUTORIALONE"));
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        mpSplash.pause();
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        mpSplash.start();
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        setContentView(R.layout.activity_main);
    }

}
  • 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-10T01:31:33+00:00Added an answer on June 10, 2026 at 1:31 am

    inside the onCreate() with the line

    MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.explosion);
    

    is a local variable.

    replace it with

    this.mpSplash = MediaPlayer.create(this, R.raw.explosion);
    

    * when NullPointerException occured.

    in onDestroy()

    You called

    mpSlash.release()

    which is not yet initialized but you thought it is initialized in onCreate()

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

Sidebar

Related Questions

Hi I am quite new to php but i have been following some tutorials
i have been following this tutorial for the pagerAdapter. http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ My problem is that
i have been following apps snowfall tutorial, but i am getting some issue in
I am following some tutorials online regarding the GLSL. I have been implementing the
I have been asked to migrate some code to our new asp.net web app.
I have been doing some research for using MSMQ. Following 2 gave me fundamental
I have been following a couple of articles regarding RESTful web services with WCF
I have been following the validation for Entry boxes from here . The code
I have been reading the following text on the Android Developers Site, specifically under
I am in the process of learning cocos2d-android. I have been following a tutorial

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.