How to resolve nullpointer exception being gotten in Check Permission
<p>Am presently using Marshmallow SDK and am  check that the user has granted permission for every location call that i make but i get this exception of null pointer every time i request for location. This is how i used the check permission</p>

<pre><code> if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            }

            if ( Build.VERSION.SDK_INT &gt;= 23 &amp;&amp;
                    ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED &amp;&amp;
                    ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                //return 0 ;
            }
</code></pre>

<p>my log cat is below</p>

<pre><code>08-19 00:57:16.537 10992-10992/com.ant.henry.gatesng W/System.err:     java.lang.NullPointerException
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at android.content.ContextWrapper.checkPermission(ContextWrapper.java:545)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at android.support.v4.content.ContextCompat.checkSelfPermission(ContextCompat.java:432)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at com.ant.henry.gatesng.GPSService.getLocation(GPSService.java:76)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at com.ant.henry.gatesng.CapeActivity.nearBy(CapeActivity.java:190)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
08-19 00:57:16.539 10992-10992/com.ant.henry.gatesng W/System.err:     at android.view.View$1.onClick(View.java:3851)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.view.View.performClick(View.java:4471)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.view.View$PerformClick.run(View.java:18789)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.os.Handler.handleCallback(Handler.java:808)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:103)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.os.Looper.loop(Looper.java:193)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5323)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
08-19 00:57:16.540 10992-10992/com.ant.henry.gatesng W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
08-19 00:57:16.541 10992-10992/com.ant.henry.gatesng W/System.err:     at dalvik.system.NativeStart.main(Native Method)
</code></pre>