Android 애플리케이션에서 AssetManager를 사용하여 이미지를 읽으려는 클래스가 있습니다. 다른 클래스에서이 클래스를 호출해야합니다. 나는 오류가 지역 변수 플래그를 얻고있다AssetManager Drawable에 대한 로컬 변수가 초기화되지 않았습니다.
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;
}}
가 초기화되지 않았을 수 있습니다. 이 오류를 방지하는 방법을 알려주십시오. 많은 감사드립니다. JVM이이
flag = Drawable.createFromStream(stream, nextImageName);
라인이 실행됩니다 확신 할 수 없기 때문에