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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:05:41+00:00 2026-06-05T16:05:41+00:00

Hello i’m a new coder to android. I have a program that Plays Pauses

  • 0

Hello i’m a new coder to android. I have a program that “Plays” “Pauses” and “Stops” a local .mp3 file. Ive found the source from this website here.

http://android-er.blogspot.com/2010/07/android-mediaplayer.html

So I post in the code and everything seems to work great until I actually hit play and get an error.

Ive tried to read the error but cant figure out what exactly its saying?

My error is this(logcat):

06-12 12:02:38.810: E/AndroidRuntime(4190): FATAL EXCEPTION: main
06-12 12:02:38.810: E/AndroidRuntime(4190): java.lang.NullPointerException
06-12 12:02:38.810: E/AndroidRuntime(4190):atcom.reg.ihigh.Cocaine$1.onClick(Cocaine.java:53)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.view.View.performClick(View.java:2485)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.view.View$PerformClick.run(View.java:9089)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.os.Handler.handleCallback(Handler.java:587)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.os.Looper.loop(Looper.java:123)
06-12 12:02:38.810: E/AndroidRuntime(4190): at android.app.ActivityThread.main(ActivityThread.java:3806)
06-12 12:02:38.810: E/AndroidRuntime(4190): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 12:02:38.810: E/AndroidRuntime(4190): at java.lang.reflect.Method.invoke(Method.java:507)
06-12 12:02:38.810: E/AndroidRuntime(4190): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-12 12:02:38.810: E/AndroidRuntime(4190): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-12 12:02:38.810: E/AndroidRuntime(4190): at dalvik.system.NativeStart.main(Native Method)

Class

package com.reg.ihigh;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Cocaine extends Activity {
    MediaPlayer mediaPlayer;
     Button buttonPlayPause, buttonQuit;
     TextView textState;

     private int stateMediaPlayer;
     private final int stateMP_NotStarter = 0;
     private final int stateMP_Playing = 1;
     private final int stateMP_Pausing = 2;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.drugg);

          buttonPlayPause = (Button)findViewById(R.id.playButton);
          buttonQuit = (Button)findViewById(R.id.quitButton);
          textState = (TextView)findViewById(R.id.state);

          buttonPlayPause.setOnClickListener(buttonPlayPauseOnClickListener);
          buttonQuit.setOnClickListener(buttonQuitOnClickListener);

          initMediaPlayer();

      }

      private void initMediaPlayer()
      {
       mediaPlayer = new  MediaPlayer();
          mediaPlayer = MediaPlayer.create(Cocaine.this, R.raw.cocaine);
          stateMediaPlayer = stateMP_NotStarter;
          textState.setText("- IDLE -");
      }

      Button.OnClickListener buttonPlayPauseOnClickListener
       = new Button.OnClickListener(){

       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(stateMediaPlayer){
        case stateMP_NotStarter:
         mediaPlayer.start();
         buttonPlayPause.setText("Pause");
         textState.setText("- PLAYING -");
         stateMediaPlayer = stateMP_Playing;
         break;
        case stateMP_Playing:
         mediaPlayer.pause();
         buttonPlayPause.setText("Play");
         textState.setText("- PAUSING -");
         stateMediaPlayer = stateMP_Pausing;
         break;
        case stateMP_Pausing:
         mediaPlayer.start();
         buttonPlayPause.setText("Pause");
         textState.setText("- PLAYING -");
         stateMediaPlayer = stateMP_Playing;
         break;
        }

       }
      };

      Button.OnClickListener buttonQuitOnClickListener
     = new Button.OnClickListener(){

      @Override
      public void onClick(View v) {
       // TODO Auto-generated method stub
       mediaPlayer.stop();
       mediaPlayer.release();
       finish();
      } 
      };

}

Xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"

/>
<Button
android:id="@+id/playButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:text="Play"/>
<Button
android:id="@+id/quitButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:text="Quit"/>
<TextView
android:id="@+id/state"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

EDIT FIX:

When I converted my original mp3’s to compress them some how it got corrupted over the copy proccess to the raw folder. So I just recompressed copied over and bam. Everything works! Thanks @MattWolfe

  • 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-05T16:05:44+00:00Added an answer on June 5, 2026 at 4:05 pm

    The MediaPlayers create() method says that:

    Returns a MediaPlayer object, or null if creation failed 
    

    That is the case thats happening in your case. Read this answer and this answer for further information about resolving your issue.

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

Sidebar

Related Questions

Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello everyone i am developing an quiz based app in android and i have
Hello, Im working on a solution for Android that will record calls (both out
Hello dearest community. I have trouble in the last two days, that I can't
Hello I have a air for android project going and I am wanting to
Hello frnds I have windows mobile application, that retrieves location info. Now i want
hello i have a app that connects and post to user wall but when
Hello I have an example that works properly: $(function() { $(#treegrid).jqGrid({ url: 'tree2.json', datatype:

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.