मेरे पास बिटमैप है जो कि एक नई गतिविधि में दिखने की ज़रूरत है, इसलिए मैं इसे देखता हूं और खुली गतिविधि में मैं इसे लोड करने का प्रयास करता हूं लेकिन मुझे एक नल पॉइंटर एक्सेप्शन मिलता है।एंड्रॉइड, अलग-अलग गतिविधियों से कैश में बिटमैप सहेजना और लोड करना
File cacheDir = getBaseContext().getCacheDir();
File f = new File(cacheDir, "pic");
try {
FileOutputStream out = new FileOutputStream(
f);
pic.compress(
Bitmap.CompressFormat.JPEG,
100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(
AndroidActivity.this,
OpenPictureActivity.class);
startActivity(intent);
और उसके बाद नई गतिविधि में मैं इसे खोलने का प्रयास करें:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
File cacheDir = getBaseContext().getCacheDir();
File f = new File(cacheDir, "pic");
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(fis);
ImageView viewBitmap = (ImageView) findViewById(R.id.icon2);
viewBitmap.setImageBitmap(bitmap);
setContentView(R.layout.open_pic_layout);
आपको यह उल्लेख करना चाहिए कि कौन सी रेखा NullPointerException को फेंकता है। –