ShaAk
ShaAk

Reputation: 190

Run-time exception (java.lang.NoSuchMethodError) was fired when using the method checkSelfPermission

Following exception was fired when using the method checkSelfPermission. The targetSDKVersion is 21 for the application.

FATAL EXCEPTION: main Process: app.Rvamd.RecoverAllMyDeletedFile, PID: 3700 java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/app.Rvamd.RecoverAllMyDeletedFile-1/base.apk)

Does anybody have idea on this? The method was invoked properly for another application in same emulator device. Apart from this, can I know how support library methods are selected by phone/emulator (method is invoked properly for some application while others aren't) ?

The code is as below

     if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.READ_CONTACTS},
                        MY_PERMISSIONS_REQUEST_READ_CONTACTS);
                return;


        }

Upvotes: 1

Views: 1083

Answers (1)

Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42690

You might need to upgrade compileSdkVersion to 23. This is because runtime permission feature is added since API 23.

Upvotes: 1

Related Questions