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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:22:47+00:00 2026-06-14T20:22:47+00:00

I am trying to make a music player in java. I have gone to

  • 0

I am trying to make a music player in java. I have gone to numerous websites and looked at resources to see how it works, but AudioInputStream gives me a nullPointerException in a place where I least expect it! It seems that no one has asked this question before (in addition, I don’t have enough rep to comment so I had to make this a separate question), so I’ll show you the code where it’s going wrong:

Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.getInputStream(new File("mywav.wav"));
clip.open(ais);
clip.start();

I surrounded this with Thread and started the Thread, so it should play fully. But, I get a nullPointerException at the line “AudioInputStream ais = AudioSystem.getInputStream(….”

  • 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-14T20:22:48+00:00Added an answer on June 14, 2026 at 8:22 pm

    1) You can load your sound from where-ever. A folder called “sound” is just a convenience, such as a folder called “images” for your art graphics.

    2) I think you will have better luck if you use the URL instead of the file as your input source.

    Thus:

    URL url = this.getClass().getResource("mywav.wav");
    AudioInputStream aiStream = AudioSystem.getAudioInputStream(url);   
    

    One obscure problem that comes up (and I’ve helped about a dozen people making the same error) is that when you do it your way, you create the intermediate step where there is an InputStream. If you check the JavaDocs for AudioSystem.getAudioInputStream(url) vs AudioSystem.getAudioInputStream(inputStream), you will see that the InputStream has to be a “markable” file, and there are no guarantees of this. With the URL form, there is no such test or requirement.

    Here are the links, for easier perusal.
    http://docs.oracle.com/javase/6/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream(java.net.URL)
    http://docs.oracle.com/javase/6/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream(java.io.InputStream)

    It seems prior to Java 7, for some reason, there was a default such that the system “knew” how to handle wav files, but this default is no longer in place and many folks who used your way of getting their AudioInputStream from an InputStream suddenly found their sound code broken. There’s even an offical Oracle bug report on this: #7095006

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

Sidebar

Related Questions

I am trying to make an Android music player. To make things easier, I
I have been trying to make a music streaming website. I store all the
I'm trying to make a music-player where i use almost all the area on
I am trying to create a music player/centre online. I have a player that
I am trying to make music play in my app and have a song
I am trying to make a simple application of a music player with simple
I'm trying to make a simple sudoku but I have a problem with the
I am trying to make an audio player using jquery and seem to have
I am trying to make a new file format for music. It needs to
I'm making a little music app. I`m trying to make my layout as flexible

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.