我有一个类,我试图在 Android 应用程序中使用 AssetManager 读取图像。我必须在另一个类中调用这个类。
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(); // get app's AssetManager
InputStream stream; // used to read in Image images
String nextImageName = imgName;
Drawable flag;
try {
// get an InputStream to the asset representing the next Image
stream = assets.open(nextImageName + ".jpg");
// load the asset as a Drawable and display on the objImageView
flag = Drawable.createFromStream(stream, nextImageName);
} // end try
catch (IOException e) {
Log.e(TAG, "Error loading " + nextImageName, e);
} // end catch
return flag;
}}
我收到错误局部变量标志可能尚未初始化。请告诉我如何避免这个错误。提前非常感谢。