java - Local variable may not have been initialized for AssetManager Drawable -
this question has answer here:
i have class trying read images using assetmanager in android application.i have call class in class.
import android.app.activity; import android.content.res.assetmanager; import android.graphics.drawable.drawable; import android.util.log; import java.io.ioexception; import java.io.inputstream; public class assetactivity extends activity { private static final string tag = "assetactivity"; public drawable getimage(string imgname) { assetmanager assets = getassets(); // app's assetmanager inputstream stream; // used read in image images string nextimagename = imgname; drawable flag; try { // inputstream asset representing next image stream = assets.open(nextimagename + ".jpg"); // load asset drawable , display on objimageview flag = drawable.createfromstream(stream, nextimagename); } // end try catch (ioexception e) { log.e(tag, "error loading " + nextimagename, e); } // end catch return flag; }}
i getting error local variable flag may not have been initialized. please tell me how avoid error. lot in advance.
you need set variable flag initial value, null.
in case there exception value not set in try block due compiler complaints.
Comments
Post a Comment