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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:53:53+00:00 2026-05-30T17:53:53+00:00

I have been working on a simple app to play a random sound byte

  • 0

I have been working on a simple app to play a random sound byte on button click and pretty much have everything working correctly, but for some reason the app force closes randomly after a click event and I am unable to figure out what is causing the issue as I am still relatively new to android programming. Any assistance would be greatly appreciated!

My Code:

public class Soundboard extends Activity {
    private SoundManager mSoundManager;

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

        // FULLSCREEN CODE
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);

        mSoundManager = new SoundManager();
        mSoundManager.initSounds(getBaseContext());
        mSoundManager.addSound(0, R.raw.sound1);
        mSoundManager.addSound(1, R.raw.sound2);
        mSoundManager.addSound(2, R.raw.sound3);
        mSoundManager.addSound(3, R.raw.sound4);
        mSoundManager.addSound(4, R.raw.sound5);
        mSoundManager.addSound(5, R.raw.sound6);
        mSoundManager.addSound(6, R.raw.sound7);
        mSoundManager.addSound(7, R.raw.sound8);
        mSoundManager.addSound(8, R.raw.sound9);
        mSoundManager.addSound(9, R.raw.sound10);

        ImageButton SoundButton1 = (ImageButton)findViewById(R.id.Btn_Push);
        SoundButton1.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {

        Random r = new Random();
        int x = r.nextInt(11);
        mSoundManager.playSound(x);

    }
});
}
}

Logcat:

W/dalvikvm(1146): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(1146): FATAL EXCEPTION: main
E/AndroidRuntime(1146): java.lang.NullPointerException
E/AndroidRuntime(1146):     at com.tmapps.twss.SoundManager.playSound(SoundManager.java:37)
E/AndroidRuntime(1146):     at com.tmapps.twss.Soundboard$1.onClick(Soundboard.java:49)
E/AndroidRuntime(1146):     at android.view.View.performClick(View.java:2485)
E/AndroidRuntime(1146):     at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime(1146):     at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(1146):     at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(1146):     at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(1146):     at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(1146):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(1146):     at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(1146):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(1146):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(1146):     at dalvik.system.NativeStart.main(Native Method)
  • 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-05-30T17:53:54+00:00Added an answer on May 30, 2026 at 5:53 pm

    Well, you have:

    r.nextInt(11)
    

    Which gets random numbers from 0-10, but you only have sounds for 0-9. So when you happen to hit 10, you get a NullPointerException.

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

Sidebar

Related Questions

I have been working on a simple Java app. I had it compiling and
I have been struggling to get a simple autocomplete working with my Rails app
I have been working on a Core Data iOS app that works perfectly through
I have been working with iPhone app as developer and now my PM(Project Manager)
I just started learning Backbone.js, and have been working on (what else) a simple
I am new to Silverlight and have been working with Simple MVVM to create
I have been working on an iPhone App for a couple of weeks now
I have been struggling with what I perceive to be a simple problem: Working
OK, well I've been working on a simple app that allows users to save
Okay so i have been working on this app for a couple months now

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.