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

  • Home
  • SEARCH
  • 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 6568255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:27:18+00:00 2026-05-25T14:27:18+00:00

Following is some function : jTextField1.setEnabled(false); jTextField2.setEnabled(false); jTextField3.setEnabled(false); jComboBox1.setEnabled(false); jComboBox2.setEnabled(false); String samplingRate = jTextField1.getText();

  • 0

Following is some function :

        jTextField1.setEnabled(false);
        jTextField2.setEnabled(false);
        jTextField3.setEnabled(false);
        jComboBox1.setEnabled(false);
        jComboBox2.setEnabled(false);
        String samplingRate = jTextField1.getText();
        String sampleSize = jTextField2.getText();
        String channels = jTextField3.getText();
        String endian = (String)jComboBox1.getSelectedItem();
        String outputFormat = (String)jComboBox2.getSelectedItem();
        AudioFormat outputAudioFormat = new AudioFormat( Float.parseFloat(samplingRate) , Integer.parseInt(sampleSize) , Integer.parseInt(channels) , true , Boolean.parseBoolean(endian) );
        AudioInputStream newAIS;  // newAIS declared Here 
        try {
         newAIS = AudioSystem.getAudioInputStream(outputAudioFormat,  AudioSystem.getAudioInputStream(new File(originalFile) ) );
         // The above statement converts the data in the original file to the data filled by the user
        } catch( Exception exc ){
            System.out.println( exc );
          }
        String outLoc = null;
        JFileChooser saveLoc = new JFileChooser();
        int option = saveLoc.showSaveDialog(this);
        if( option == JFileChooser.APPROVE_OPTION ) 
            outLoc = saveLoc.getSelectedFile().getAbsolutePath();
        try {
        if( outputFormat == "AIFF" ) {
          AudioSystem.write(newAIS, AudioFileFormat.Type.AIFF, new File(outLoc) ); 
          // the above line gives an error saying that newAis might not have been intialized                  
        } else if( outputFormat == "WAVE") {
            AudioSystem.write(newAIS, AudioFileFormat.Type.WAVE, new File(outLoc) );
            // the above line gives an error saying that newAis might not have been intialized     
          } else if( outputFormat == "AU") {
              AudioSystem.write(newAIS, AudioFileFormat.Type.AU, new File(outLoc) );
              // the above line gives an error saying that newAis might not have been intialized     
            } else if( outputFormat == "SND") {
                AudioSystem.write(newAIS, AudioFileFormat.Type.SND, new File(outLoc) );
                // the above line gives an error saying that newAis might not have been intialized     
              }
        } catch( Exception exc ){
          }

In the above snippet i declare a variable newAIS of type AudioInputStream. (12th statement from starting) In the next statement the variable newAIS is intialized. When i reach the if-else part variable newAIS is said to be uninitialized by the IDE and it gives an error saying newAis might not have been initialized Why is it so ? The variable newAIS has function scope.

On the other hand if i declare variable newAIS global , the IDE doesn’t spot an error.

Why does this happen ?

  • 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-25T14:27:18+00:00Added an answer on May 25, 2026 at 2:27 pm

    Yes, it’s in scope, but it may not have been initialized – if an exception occurs, then instead of the variable being assigned a value, you’re just printing out the exception and continuing. What value would you expect newAIS to have in that case?

    Local variables are checked for definite assignment before being read, but instance / static variables aren’t.

    Note that if you didn’t keep going in the fact of an exception, but instead threw another exception up to the caller, or just didn’t catch it in the first place, or returned, it would be fine. It’s not clear what exceptions you’re really trying to handle – catching Exception is a bad practice in general.

    You could just assign the variable a value to start with:

    AudioInputStream newAIS = null;
    

    … but do you really want to keep going if the assignment fails?

    Also note that you’re currently comparing strings using ==, which is also a bad idea. This:

    if (outputFormat == "AIFF")
    

    should probably be:

    if (outputFormat.equals("AIFF"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling
I use a function that sends emails to some users. I use the following
Following some examples, I have a function that gets triggered on the 'register_deactivation_hook'. This
Consider the following jasmine spec: describe(something.act(), function() { it(calls some function of my module,
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have been following some MVC tutorials that connect to a sql mdf database
Today I was following some instructions to install a software in Linux. There was
Hi I am quite new to php but i have been following some tutorials
I have some function taht is caller periodically: var func = function() { alert('Hello
After reading some examples on stackoverflow, and following some of the answers for my

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.