In my snippet, I started the startActivityforresult goal to capture photos. I overriden the callbackActivityResult method in the fragment class. I applied the onActivityResult callback in the main activity for some other purposes. My problem is the onActivityResult snippet after execution invokes the onActivityResult actions and returns a null pointer exception. Fragment onactivityresment method
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { prof_bitmap = null; if (requestCode == 0) { Log.e("" ,"entered activity Result Code 0"); Uri photoUri = data.getData(); if (photoUri != null) { String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().getContentResolver().query( photoUri, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.e("" ,"File Path" +filePath); prof_bitmap = setImage(filePath); } } if (requestCode == 1) { Log.e("" ,"entered activity Result Code 1"); Bitmap bitmap = (Bitmap) data.getExtras().get("data"); prof_bitmap = bitmap; Log.e("" ,"entered activity Result Code 1"+bitmap); profile_pic.setImageBitmap(bitmap); } } }
OnActivityResult action
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("" ,"called onActivityResult in main"); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); }
How to call only the onactivityresult method for a fragment?
MY Logcat
ResultInfo result execution error {who = null, request = 1, result = -1, data = Intent {act = inline-data dat = content: // media / external / images / media / 222 (has additional functions)}} in action {com.mobiotics.tvbuddydemo / com.mobiotics.tvbuddydemo.TVBuddyMainActivity}: java.lang.NullPointerException
source share