我似乎无法弄清楚这一点.我有2个具有不同特征的java类,每个类调用BitmapFactory.decodeResource来获取相同的图像资源,一个返回位图而另一个返回null.两个类都在同一个包中.
这是有效的类,它调用BitmapFactory.decodeResource返回位图.我只包含相关代码.
package advoworks.test;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainScreen extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = MainScreen.class.getSimpleName();
public MainScreen(Context context) {
super(context);
Bitmap bitmap;
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
//adding the callback (this) to the surface holder to intercept events;
getHolder().addCallback(this);
// make the GamePanel focusable so it can handle events
setFocusable(true);
}
}
Run Code Online (Sandbox Code Playgroud)
这是不起作用的类.BitmapFactory.decodeResource在调试中返回NULL.我只包括我觉得相关的代码.
package advoworks.test;
import android.content.res.Resources;
import android.graphics.Bitmap; …Run Code Online (Sandbox Code Playgroud)