Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Playing an AudioClip returning NullPointerException?  (Read 2104 times)
0 Members and 1 Guest are viewing this topic.
Offline Shane75776
« Posted 2011-12-04 22:24:51 »

I am trying to play an audio clip for a game I am making within an "AudioManager" that handles all of my audio.

For some reason whenever I call the playBBounce() method I get a null pointer exception on my url.

What I dont understand is why I am getting that error. I even tried changing the url to "audio/bubble.wav"

Thanks in advance.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
import java.applet.AudioClip;
import java.net.URL;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class AudioManager
{
   AudioClip clip;
   
   public void playBBounce()
   {
      try
      {
         URL url = this.getClass().getClassLoader().getResource("/audio/bubble.wav");
         AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
         Clip clip = AudioSystem.getClip();
         clip.open(audioIn);
         clip.start();  // play once


Here is a picture of the project and error in eclipse also.
http://imgur.com/vA1zo

Check out my Snipping Tool++ ! An advanced snippet/screenshot/text uploading tool! Meant to replace the windows snipping tool.

Check out Pixel Rain My most recent Swing based game!
Offline Shane75776
« Reply #1 - Posted 2011-12-04 22:47:52 »

Nvm, Problem solved.

I change it to getClass().getResource() rather than getClass().getClassLoader().getResource()

and it worked.

Check out my Snipping Tool++ ! An advanced snippet/screenshot/text uploading tool! Meant to replace the windows snipping tool.

Check out Pixel Rain My most recent Swing based game!
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1599 views)
2018-06-10 19:43:48

EgonOlsen (1700 views)
2018-06-10 19:43:44

EgonOlsen (1154 views)
2018-06-10 19:43:20

DesertCoockie (1582 views)
2018-05-13 18:23:11

nelsongames (1182 views)
2018-04-24 18:15:36

nelsongames (1705 views)
2018-04-24 18:14:32

ivj94 (2473 views)
2018-03-24 14:47:39

ivj94 (1690 views)
2018-03-24 14:46:31

ivj94 (2771 views)
2018-03-24 14:43:53

Solater (911 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!