我有一個應用程序,在我正在拍照(等)的活動。nullpointerexception當不拍照
現在,當我按下按鈕把它打開camera.If我會按後退按鈕或取消按鈕(未拍照)的照片,它崩潰並給出
空指針
和
未能提供結果ResultInfo
在這一行:
Bitmap photo = (Bitmap) data.getExtras().get("data");
我用:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == CAMERA_REQUEST){
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
blobvalue = stream.toByteArray();
Bundle extras = new Bundle();
Intent k=new Intent(this,MainActivity.class);
extras.putParcelable("Bitmap", photo);
k.putExtras(extras);
}
if (requestCode == RESULT_CANCELED) {
}
}
,並在我的適配器:
ImageView myImage=(ImageView) convertView.findViewById(R.id.myimage);
final Bitmap image;
if(theItems.getImagemyItems() != null)
{
byte []temp = theItems.getImagemyItems();
image = BitmapFactory.decodeByteArray(temp, 0, temp.length);
myImage.setImageBitmap(image);
}
else
{
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
myImage.setImageBitmap(image);
}
至於我記得,上述用於workd用於此目的。 我不知道還有什麼要做。
你可以發佈堆棧跟蹤。 – Raghunandan
你不是在測試resultCode來知道用戶是否按下了。 – njzk2