लौटने पर मुझे यह पता लगाना प्रतीत नहीं होता है। मेरे पास अलग-अलग विशेषताओं वाले 2 जावा वर्ग हैं, प्रत्येक एक ही छवि संसाधन प्राप्त करने के लिए बिटमैपफैक्टरी.decodeResource को कॉल करते हुए, कोई बिटमैप देता है जबकि दूसरा रिटर्न शून्य करता है। दोनों कक्षाएं एक ही पैकेज में हैं।एंड्रॉइड: BitmapFactory.decodeResource शून्य
यहां वह वर्ग है जो काम करता है, यह बिटमैप फैक्टरी.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);
}
}
यहां वह वर्ग है जो काम नहीं करता है। BitmapFactory.decodeResource डीबग में एक पूर्ण लौटाता है। मैंने केवल कोड शामिल किया है जो मुझे लगा वह प्रासंगिक था।
package advoworks.test;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;
public class Segment {
private int x;
private int y;
private Bitmap bitmap;
public Segment(int x, int y) {
Log.d(TAG, "Creating Segment");
try {
this.bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
} catch (Exception e) {
Log.d(TAG,"Error is " + e);
}
this.x = x;
this.y = y;
Log.d(TAG, "Created Segment");
}
}
कोई भी सुराग किसी को भी?
आप logcat में किसी भी त्रुटि मिल रहा है? – blessenm
नहीं, मुझे लॉगकैट में कोई त्रुटि नहीं मिल रही है :( – Kevin
आपको एक ही ऐप में दो बार एक ही संसाधन को लोड करने की आवश्यकता क्यों है। इसे एक बार लोड करें और आपको इसकी आवश्यकता वाले सभी स्थानों पर इसका संदर्भ दें। – Ronnie