permission cannot be null or empty

java.lang.NullPointerException: permission cannot be null or empty

Recently a RecyclerView CRUD operation was created in which the image functionality pick from camera or gallery was also used. Previously, the same CRUD operation was performed in ListView, which was the same as selecting an image in the camera or gallery and displaying it in ListView.

Both recyclerView and Listview are working perfectly but while doing some version checking on that bug and unfortunately crash application showed errors like “java.lang.NullPointerException: Permission cannot be null or empty”

But when try other devices working perfectly then some version crop image is not getting permission and getting errors like “java.lang.NullPointerException: Permission cannot be null or empty”.

So today we’ll solve this type of error in android studio.

Error log

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.recyclerviewwithimage, PID: 10652
    java.lang.NullPointerException: permission cannot be null or empty
        at android.content.pm.PackageManager.buildRequestPermissionsIntent(PackageManager.java:2689)
        at android.app.Activity.requestPermissions(Activity.java:3925)
        at com.example.recyclerviewwithimage.MainActivity.requestCameraPermission(MainActivity.java:112)
        at com.example.recyclerviewwithimage.MainActivity.access$100(MainActivity.java:33)
        at com.example.recyclerviewwithimage.MainActivity$1.onClick(MainActivity.java:81)
        at android.view.View.performClick(View.java:5212)
        at android.view.View$PerformClick.run(View.java:21214)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5619)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)

Here it says “java.lang.NullPointerException: Permission cannot be null or empty” when clicking on pic image from camera or gallery.

You can solve this type of error just add in below 2 permission line in your activity.

    cameraPermission=new String[]{Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE};
    storagePermission=new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};

For example

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    cameraPermission=new String[]{Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE};
    storagePermission=new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
}

Leave a Reply