0

I am trying to apply permission in Android 6.0(Marshmallow).

But I have below issue.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference
        at android.content.ContextWrapper.checkPermission(ContextWrapper.java:637)
        at android.support.v4.content.ContextCompat.checkSelfPermission(ContextCompat.java:387)
        at com.xxxxx.xxxxx.VSFunctionActivity.Scan(VSFunctionActivity.java:530)
        at com.xxxxx.xxxxx.VSFunctionActivity.GetPairedList(VSFunctionActivity.java:519)

The following codes are part of the problem.

public void Scan(int scantime)
{
    // Scan function
    if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (Variable.mb_Debug) {
            Log.i(Variable.TAG, "Location permissions has NOT been granted. Requesting permissions.");
        }
        requestLocationPermission();
    }

VSFunctionActivity's line 530 is if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED.

<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="23" />

I already changed minSdkVersion to "23" from "18". But I can't fix it.

I use Android Studio 1.4 beta2.

Do you have any solution or idea? Please share your knowledge.

Regards

  • Have you added this to your build.gradle? `com.android.support:support-v4:23.0.1` – Kise Oct 05 '15 at 09:29
  • because you forgot to add if(Build.VERSION.SDK_INT >= 23) // Scan function if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (Variable.mb_Debug) { Log.i(Variable.TAG, "Location permissions has NOT been granted. Requesting permissions."); } requestLocationPermission(); – Aayushi Oct 05 '15 at 09:32
  • I already add "compile 'com.android.support:support-v4:23.0.1'". And I add "if(Build.VERSION.SDK_INT >= 23)". But I have problem yet. – KYOSEON LEE Oct 05 '15 at 09:39
  • See this link for more information https://developer.android.com/training/permissions/requesting.html – Kise Oct 05 '15 at 09:46

0 Answers0