Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointer exception while taking a picture from a fragment in android
    text
    copied!<p>Can someone tell me why is this piece of code giving me a null pointer exception</p> <p>ImageFradment is used to initiate the camera intent. This fragment is hosted in another activity</p> <p>1</p> <pre><code>public class ImageFragment extends Fragment{ private Uri imageUri; private String mPath; private ImageView image; Bitmap bitmap = null; private File tempPhoto; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_image, container, false); ImageButton snap=((ImageButton)v.findViewById(R.id.snap)); image = ((ImageView) v.findViewById(R.id.image)); snap.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); String path = Environment.getExternalStorageDirectory() + "/spot"; File photopath = new File(path); if (!photopath.exists()) { photopath.mkdir(); } File imagePath = new File(photopath, System.currentTimeMillis()+ ".png"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imagePath)); imageUri = Uri.fromFile(imagePath); getActivity().startActivityForResult(intent, 100); } }); return v; } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == 100 ) { imageUri = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().getContentResolver().query(imageUri, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); image.setImageBitmap(BitmapFactory.decodeFile(picturePath));*/ else { bitmap = BitmapFactory.decodeFile(mPath); } } </code></pre> <p>Error Log:</p> <pre><code>1-20 12:25:43.151: E/AndroidRuntime(11717): FATAL EXCEPTION: main 11-20 12:25:43.151: E/AndroidRuntime(11717): java.lang.RuntimeException: Unable to resume activity {com.example.makemyday/com.example.makemyday.ActionDetailActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131073, result=-1, data=null} to activity {com.example.makemyday/com.example.makemyday.ActionDetailActivity}: java.lang.NullPointerException 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.access$700(ActivityThread.java:141) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.os.Handler.dispatchMessage(Handler.java:99) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.os.Looper.loop(Looper.java:137) 11-20 12:25:43.151: E/AndroidRuntime(11717): at android.app.ActivityThread.main(ActivityThread.java:5103) 11-20 12:25:43.151: E/AndroidRuntime(11717): at java.lang.reflect.Method.invokeNative(Native Method) 11-20 12:25:43.151: E/AndroidRuntime(11717): at java.lang.reflect.Method.invoke(Method.java:525) 11-20 12:25:43.151: E/AndroidRuntime(11717): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 11-20 12:25:43.151: E/AndroidRuntime(11717): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 11-20 12:25:43.151: E/AndroidRuntime(11717): at dalvik.system.NativeStart.main(Native Method) 11-20 12:25:43.151: E/AndroidRuntime(11717): Caused by: java.lang.RuntimeException: Failure delivering result </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload