An error that I don't get

Hi,
Below is a member that is supposed to play an audio clip. The debugger complains about the line in the second try statement. The error messsage says: "variable clipURL might not have been initialized". What is wrong? Didn't I just initialize clipURL in the preceeding statement?
public void Play(JPanel[] channels){
        Clip clip;
     AudioInputStream audioInputStream = null;
        java.net.URL clipURL;
        try{
            clipURL = new java.net.URL("File:C:\\Documents and Settings\\Pingen\\Desktop\\sound.wav");
        catch(Exception e){
        try{
            audioInputStream = AudioSystem.getAudioInputStream(clipURL);       //Here is the line I'm talking about.
        catch(Exception e){
        AudioFormat format = audioInputStream.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, format);
        clip = (Clip) AudioSystem.getLine(info);
        clip.open(audioInputStream);
        clip.start();
    }Regards,
Pingen

>
The debugger complains about the line in the second try statement. The error messsage says: "variable clipURL might not have been initialized". What is wrong? Didn't I just initialize clipURL in the preceeding statement? No, because if an exception is thrown in the first try block, then control might have flowed to the catch block before clipURL has been set.
By the way:
1) Don't have empty catch blocks like that. At the very least, put this in:
e.printStackTrace();If something goes wrong, you need to know about it!
2) You haven't structured the flow of control well. What if the URL is bad and you end up with a bad or null clip URL. Do you really want to try to get the audio output stream from it? Suppose you can't get the audio output stream, do you really want to try to play the clip?
The whole point of try/catch blocks is to help you recover from errors, but you've set it up so you don't recover, you just keep plowing forward.
Ask yourself how you'd recover from an error at any particular step that might throw an exception. Then you could restructure accordingly. For example, if any exception leads to "just do nothing, and don't affect the calling method", then put all the code in a single try block, and have a single catch block that just prints an error message. If a bad URL means that you'd rather play a default clip, then set that default clip's URL in the first catch block.

Similar Messages

  • I'm trying to compress a file but I get an error that "I don't have permission to access dovecot."  How do I get this permission?

    I'm trying to compress a file but I get an error that "I don't have permission to access dovecot."  How do I get this permission?

    I ended up doing just as you said and downloading the program seperately.  However, I'd like to point out that after I downloaded the server.app to my MBA it did allow me to compress it.  For some reason it wouldn't let me do it from the server so I could airdrop it over.  I'd only get the error previously mentioned.  Must be a server thing eh?

  • For my user id, I have the authorization for the transaction, but still iam getting the error that, you don't have authorization, plz suggest?

    Hello ,
    For my user id, I have the authorization for the transaction, but still iam getting the error that, you don’t have authorization, plz suggest?????
    Thnks

    Hello Sampath,
    after you have received the error message about the no authorization, run transaction SU53.
    This transaction shows which authorization has failed last time.
    Best regards,
    Laszlo

  • I have 2 photo books in iPhoto. Is there some way of storing them elsewhere on my computer so that they don't get accidentally deleted?

    I have 2 photo books in iPhoto. Is there some way of storing them elsewhere on my computer so that they don't get accidentally deleted?

    Yes.  This tutorial describes how to go about it: #9a - Archiving an iPhoto 7(08)/8(09)/9(11) Book for Editing and/or Ordering at a Later Date. For future books I suggest you start out with a new library and copy the needed photos to it from your current library with iPhoto Library Manager .
    OT

  • There are times that I don't get voice instructions in Maps on my iPhone

    There are times that I don't get voice instructions in Maps on my iPhone 5s. Actually, the directions don't even advance automatically as I expect. Can anyone explain why this happens? How do I correct this? It's dangerous to drive and look at the iPhone screen at the same time, much less manually advancing the the directions!

    Put the phone in Airplane mode...this turns off all iPhone radios...but, you can go back into settings & turn WiFi back on. You can then use iMessage.
    No nasty surprises if you do that.

  • HT203433 I clicked on an app that I thought was free and it isn't. How do I stop it so that I don't get charged?

    I clicked on an app that I thought was free and it isn't (I thought I was downloading Hello Hello Spanish and instead it was Hello Hello World). How do I stop if from downloading so that I don't get charged? I've highlighted it and clicked "remove" but it keeps downloading. I do not want my school charged for this app which I didn't want! Help!

    I talked to an actual person at the Apple store and he said I could get credited for the price of the unwanted App. How do I do that?

  • Errors that I Can't get rid of?!

    Hello, I'm new to this community and have a question. Not sure if this is the right place to ask, but it's worth a try. So, I got a call from lenovo inc. somewhere in New Jersey (let's be serious please) and they told and showed me that there are a bunch of windows (I have windows 7 by the way) errors on my laptop and that my laptop is corrupt. They showed me by having me type something in a program called run. I could not delete those errors once I saw them, and they also thowed me the corrupt errors/files on the command prompt by typing in something. They said the only solution was for me to buy some security, which I don't remember what it was, but it was a while ago and it had all these plans and was very expensive ranging from like $200-$500. They said if I don't get it then there is a huge risk of hackers stealing my identity/information. They said this is the only way to get rid of it. Now, I am wondering if there is any other free way I can get rid of the errors/corrupt files wthout having to pay so much or without even paying anything at all. I could also be scammed if I had bough the security who knows, but I did see a lot of errors on the program run and I think on cmd, it said my laptop/system was like 80-90% corrupt or something like that. Now, I want to get rid of all these errors and corruption and don't want hackers anywhere near my personal information. How do I do that? Please help. Thank You!

    This is a scam.
    Neither Microsoft, nor any computer hardware manufacturer (Lenovo, in your case) monitors your system for errors... nor will they ever call you (on their own) to advise you as such.
    Most likely, they had you open the Event Viewer, which WILL display many "errors"... all of which are normal and expected.
    If you did not allow the caller to take remote control of your system, you should be safe from their shenanigans.   It must now be determined whether the so-called "errors" on your system are something that really needs to be addressed by a malware expert, or whether they're routine "warnings" that can be safely ignored.   I will leave that matter for someone else, better-qualified, to address.
    Windows 7 Pro SP1 (64-bit), avast! V7 Free, MBAM Pro, Windows Firewall, EMET, OpenDNS Family Shield, IE9 & Firefox (both using WOT & KeyScrambler), MVPS HOSTS file, SpywareBlaster, WinPatrol PLUS, SAS (on-demand scanner), Secunia PSI.
    [I am experimenting with Sandboxie, and believe computer-users who sandbox are acting prudently.]

  • HT1688 Why is it that I don't get good reception in some areas

    I don't get good reception in some areas especially around my house.

    Because the signal from your carrier is marginal there. Trees, building materials, and other things can interfere with reception.

  • Can't update to 3.6.15 because get error that I don't have permission to access some items

    When I try to update to Firefox 3.6.15, I get an error message saying I can't do so because I don't have permission to access all the items.

    * Download a new copy of the Firefox program: http://www.mozilla.com/firefox/all.html
    * Trash the current Firefox application to do a clean (re)install.
    * Install the new version that you have downloaded.
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • How can I make sure that I don't get roaming charges when traveling with my iPhone?

    Hello everyone!
    I am going to be traveling to China next week (from Canada) and I want to bring my iPhone to listen to music, read books and use for Wifi as well.  However I don't want to use it for calls, browsing etc as I don't want to get charged roaming fees for these services.
    Is there a way that I can make sure that this does not happen?  I think that if I leave my phone on Airplane mode the whole time then I'll be fine and I can find Wifi wherever I am, but I just want to see if is this in fact correct or if there is anything else I can do instead.
    As well, if I do end up taking my phone and taking out the cellular service when I'm in China, will I still be able to use iMessage to text people back home if I really have to?
    Thanks!

    Put the phone in Airplane mode...this turns off all iPhone radios...but, you can go back into settings & turn WiFi back on. You can then use iMessage.
    No nasty surprises if you do that.

  • How do I get my new Apple ID associated with an older MacBookPro so that I don't get charged more than once for a purchased app when I download it to the older computer recently upgraded to Snow Leopard?

    I recently upgraded my 2 year old MacBookPro to Snow Leopard so I could download Face Time and Final Cut ProX to it.
    I've already purchased the apps and installed on my iMAC and Macbook Air.
    After downloading Face Time I received the following mail;
    "Your Apple ID, *************, was just used to purchase FaceTime from the App Store on a computer or device that had not previously been associated with that Apple ID.
    If you made this purchase, you can disregard this email. This email was sent as a safeguard designed to protect you against unauthorised purchases.
    If you did not make this purchase, we recommend that you go to iforgot.apple.com to change your password, then see Apple ID: Tips for protecting the security of your account for further assistance.
    Regards,
    Apple"
    I don't want to be charged twice for these apps, especially Final Cut ProX, so how can I get the MacBookPro associated with the Apple ID I'm using now?
    Cheers

    This is probably a new precaution that Apple has taken to alert folks that something has occurred with their account that has not occurred before*, namely a Mac has downloaded something from their account that has not done so before. And as the notice says, if it was you doing so, then you may safely ignore the notice. Also, do not be alarmed, Apple refers to all downloads as purchases, even when they are free.
    But if you are truly concerned about the notice then you can authorize the Mac with your iTunes account, which should be the same as your MAS account. Open iTunes on the older Mac and sign into your account. Then in the Store menu choose Authorize This Computer. Now this Mac is definitely associated with your account and can now play media that you purchase from the iTunes Store as well.
    *My banks do the same thing when I pop up making a purchase with my bank cards somewhere in the world I have never made a purchase before. They call me and email me and want to know if it is indeed me using the card.

  • I keep getting an error that the connection keeps getting timed out. How do I fix this?

    When ever I click on iTunes Store icon on my iTunes I keep getting an error saying that iTunes cannot connect to the iTunes Store. Internet connection has timed out. How can I fix this issue w/o it continuing to happen which may I say is very annoying.

    you will need to follow "the old method" described at this page Moving from Aperture to Lightroom

  • Synchronous scenario: How to be sure that messages don't get lost?

    Dear all,
    my scenario is split into two parts:
    SAP -> PI  : We received a RFC (without sending a response) and split the message into single
                      files that we saved on PI filesystem
    PI -> WS:  We send the messages to a web service.
    But because we read it from file system I am not quite sure how to handle this.  If the
    web service is not available a normal synchronous web service message is normally stopped
    and can not be restarted.  How can I be sure, that the message will not getting lost?
    The only way I could see is the support that see the erroneous message an inform the business.
    Is it possible to automate the process if the web service is not reachable?
    If the web service sends an error code, I can handle this with conditions in receiver determination,
    but technical problems will just stop the message, wouldn't it?
    Regards
    Chris

    Hi,
    Syncronous messages once failed in PI can not be restarted . To inform business you can use several options :
    1. Use Interface specific alert so that when the particular interface fails alert will be triggered and sent to respective recipients.
    2. You can also right the ABAP report which sends the emails with payload for the messages which have failed . You can also shedule this report as per your need .
    Regards,
    Ganesh

  • Email, how do I protect Emails on my Treo so that they don't get deleted?

    I find that every couple of days, my received Email messages get deleted automatically.  There are some that I want saved but I can't seem to find any settings to do this.  I don't want Emails deleted unless I delete them.  Is there a way to do this?
    Post relates to: Treo 800w (Sprint)

    Yes.  This tutorial describes how to go about it: #9a - Archiving an iPhoto 7(08)/8(09)/9(11) Book for Editing and/or Ordering at a Later Date. For future books I suggest you start out with a new library and copy the needed photos to it from your current library with iPhoto Library Manager .
    OT

  • My gmail doesn't default on firefox, it get 'failed' messages that I don't get on IE, why?

    I don't have many more details....I tried to email questions to a local photographer that I researched on-line. I then tried to respond to a couple of craigslist items. I was able to add a comment on my friends blog, but when I tried her 'email' button with a more personal message it failed again. I keep getting 'failed' messages, but couldn't get any details, just 'failed'. I then opened/closed both my gmail accounts. When I opened each account and worked directly from my gmail page, I was able to send messages back and forth between my two accounts. So I tried again from another craigslist item, still the same failure. Went to IE and my email went directly to the craigslist inquiry.

    Try to update Firefox to a more recent 3.5.x or 3.6.x version (Help > Check for Updates).
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    *Shockwave Flash 10.0 r22
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/

Maybe you are looking for

  • What kind of Headphones are included with Zen Mik

    I was wondering about buying a Mp3-Player a long time, and finally decided that Zen Mikro would be the best choice to make. There is no information about the kind of headphones who are included in the package, and knowing the quality of the Headphone

  • Bootcamp and Parallels

    Can I run bootcamp and Parallels on the same Mac? How do I run Bootcamp if I've already installed Parallels? Do I have to re-format my drive and start over?

  • White border in Phone and Tablet

    Hi, I'm nearly done with a website i'm building with muse. I only want to do the desktop version since i'll update it fairly often in the future, and i don't want to update 3 versions each time. It's pretty simple, but when i view it on an iphone or

  • Is it ok to charge an itouch using an ipad charger

    Is it ok to charge an itouch (3G or 4G) using an (official) ipad charger. It says yes in the instructions but the itouch gets really hot

  • How to install IOS sdk for Xcode 3.1.1 on OS 10.5.8

    Hi I am using 10.5.8 OS. I have just installed XCode 3.1.1 from http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0 .1.1.0.3.1.3.3.1. The disk image did not have IOS sdk (for iphone/ipad simulations). Is it possible to do