BaseAdapter를 확장하는 BinderData 클래스에서 2 개의 클래스가 있습니다.이 클래스를 Activity로 확장 할 수 없습니다 (BaseAdapter로 확장해야 함). 다음 코드로 AssetActivity 클래스를 호출합니다.null asset 예외를 던지고
AssetActivity a = new AssetActivity();
Drawable image=a.getImage(imageUri);
여기 imageuri는 문자열이며 properly.In 내가 사용하고 AssetActivity 클래스에 다음 코드를 채워집니다.
public class AssetActivity extends Activity {
private static final String TAG = "AssetActivity";
public Drawable getImage(String imgName) {
String nextImageName = imgName+ ".jpg";
AssetManager assets = getAssets(); // get app's AssetManager
InputStream stream; // used to read in Image images
Drawable flag=null;
try {
// get an InputStream to the asset representing the next Image
stream = assets.open(nextImageName);
// 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;
}
}
내가 라인을 다음에서 NullPointerException이 무엇입니까 코드를 실행하고 있습니다.
AssetManager assets = getAssets();
자산 폴더에서 자산이 있고 나는 명시에 getAssets() 메서드를 호출하여 다른 클래스를 가져올 수 있어요 그 클래스는 활동을 확장합니다. 이걸 도와주세요. BinderData 클래스에서 getImage 메서드를 호출 할 때 뭔가 잘못하고 있다고 의심됩니다. 도와주세요. 감사.
Thnx를 얻을 수 있지만 안드로이드와 자바에 새로운 오전으로 U 더 자세히 설명해 수
장소. – Sid
@ 시드 오케이 .. 그 밖에 알고 싶은 것이 있습니까? 현재 활동에 해당 메소드를 배치하고 직접 호출하십시오. 'getAssets()'대신'context.getAssets()'를 사용하십시오 – Pragnani
메소드가 BaseAdapter 인 액티비티가 아니므로 메소드를 메인 클래스에 배치 할 수 없습니다. 나는 context.getAssets() 및 그것을 사용하는 방법을 이해하지 못했습니다. Activity 클래스에서 사용해야합니까? – Sid