FATAL EXCEPTION: AsyncTask #1 ,java.lang.RuntimeException: An error occurred while executing doInBackground() : I am getting this error after i am try to updated my compileSdkVersion andTargetSdkversion greater than 22. Seems like I am doing any GUI task in my doInBackground method but i am unable to figure it out. I would be much thankful for a solution.

This is my stack trace:

    E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                      Process: xy.abc.xyz.xy, PID: 15246
                      java.lang.RuntimeException: An error occurred while executing doInBackground()
      at android.os.AsyncTask$3.done(AsyncTask.java:309)
      at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
      at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
      at java.util.concurrent.FutureTask.run(FutureTask.java:242)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
     at java.lang.Thread.run(Thread.java:818)
    Caused by: java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
    at android.os.Parcel.readException(Parcel.java:1599)
    at android.os.Parcel.readException(Parcel.java:1552)
    at android.net.wifi.IWifiManager$Stub$Proxy.getScanResults(IWifiManager.java:1066) at android.net.wifi.WifiManager.getScanResults(WifiManager.java:1311)
     at xy.abc.xyz.xy.config.WlanInfoAdapter.getNewItems(WlanInfoAdapter.java:72)
                          at xy.abc.xyz.xy.android.data.ChangeableArrayAdapter$1.doInBackground(ChangeableArrayAdapter.java:78)
                          at xy.abc.xyz.xy.android.data.ChangeableArrayAdapter$1.doInBackground(ChangeableArrayAdapter.java:74)
                          at android.os.AsyncTask$2.call(AsyncTask.java:295)
                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                          at java.lang.Thread.run(Thread.java:818) 



Method in class WlanInfoAdapter.java:72 is here:



    @Override
    	protected List<WlanInfo> getNewItems() {
    		WifiManager wifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
    		List<ScanResult> scanResults = wifiManager.getScanResults();
    		List<WlanInfo> infoList = new ArrayList<>(scanResults.size());
    
    		WifiInfo connectionInfo = wifiManager.getConnectionInfo();
    
    		try {
                List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
                Map<String, WifiConfiguration> configuredNetworkIds = new HashMap<>();
                for (WifiConfiguration configuredNetwork : configuredNetworks) {
                    if (configuredNetwork.SSID != null) {
                        configuredNetworkIds.put(WlanInfo.cleanSSID(configuredNetwork.SSID), configuredNetwork);
                    } else {
                       
                        wifiManager.removeNetwork(configuredNetwork.networkId);
                    }
                }
    
                for (ScanResult scanResult : scanResults) {
                    WlanInfo wlanInfo = new WlanInfo(scanResult);
                    WifiConfiguration configuration = configuredNetworkIds.get(wlanInfo.getSSID());
                    wlanInfo.setConfiguration(configuration);
                    wlanInfo.setIsActive(configuration != null && configuration.networkId == connectionInfo.getNetworkId());
    
    
                    if (showUnknown || wlanInfo.isConfigured() || wlanInfo.isOpen()) {
                        infoList.add(wlanInfo);
                    }
                }
            }
            catch (Exception e) { e.printStackTrace(); return null; }
    		return infoList;
    	}


Method in changeableArrayAdapter.java class showing error is given below. its where getNewItems() method is called:
ChangeableArrayAdapter.java:78
ChangeableArrayAdapter.java:74


    public void triggerRefresh() {
    		AsyncTask<Void, Void, List<T>> asyncTask = new AsyncTask<Void, Void, List<T>>() {
    			@Override
    			protected List<T> doInBackground(Void... objects) {
    
    
    				return getNewItems();
    
    				//return null;
    			}
