Though variables have been initialized I get might not have been initialized error

I am having problem with the following code in an android app that I am developing. Now even though I have initialized the variables I am getting the error variable might not have been initialized.

Activity context;
context = new Activity();
SimpleSpkDetSystem alizeSystem;
try {
    InputStream configAsset = context.getApplicationContext().getAssets().open("MyConfig.cfg");
    try {
        alizeSystem = new SimpleSpkDetSystem(configAsset, context.getApplicationContext().getFilesDir().getPath());
    } catch (AlizeException e) {
        Log.e(LOG_TAG, "File not found for recording ", e);
    }
    configAsset.close();

} catch (java.io.IOException e) {
    Log.e(LOG_TAG, "File not found for recording ", e);
}
InputStream backgroundModelAsset;
try {
    backgroundModelAsset = context.getApplicationContext().getAssets().open("gmm/world.gmm");
} catch (java.io.IOException e) {
    Log.e(LOG_TAG, "File not found for recording ", e);
}
try {
    alizeSystem.loadBackgroundModel(backgroundModelAsset);
} catch (AlizeException e) {
    Log.e(LOG_TAG, "File not found for recording ", e);
}
try {
    backgroundModelAsset.close();
} catch (java.io.IOException e) {
    Log.e(LOG_TAG, "File not found for recording ", e);
}

The following are the errors I am getting

Error:(274, 13) error: variable alizeSystem might not have been initialized
Error:(274, 45) error: variable backgroundModelAsset might not have been initialized
Error:(279, 9) error: variable backgroundModelAsset might not have been initialized
Error:(274, 44) error: unreported exception IOException; must be caught or declared to be thrown
Jon Skeet
people
quotationmark

Now even though I have initialized the variables

You haven't though - not necessarily. Suppose the new SimpleSpkDetSystem(...) call throws an AlizeException. You're catching that exception and continuing - but you won't have assigned a value to alizeSystem. The same is true for all the other variables.

I suspect the solution here is not to just log exceptions and then continue as if they hadn't happened, but instead let them bubble up to the caller.

people

See more on this question at Stackoverflow