java - Wifi scanner with 20 scanning purpose -
i trying built array of class , putting values objects still showing null pointer exception.
my code :
class wifiscanreceiver extends broadcastreceiver { @suppresslint("usevalueof") public void onreceive(context c, intent intent) { list<scanresult> wifilist = wifi.getscanresults(); info = wifi.getconnectioninfo(); int k = wifilist.size(); scan_data[] data = new scan_data[k]; (int i=0;i<20;i++){ wifi.startscan(); list<scanresult> wifilist1 = wifi.getscanresults(); int l = wifilist1.size(); if (i==0){ (int j=0;j<l;j++){ data[j].ssid = wifilist1.get(j).ssid.tostring(); data[j].bssid = wifilist1.get(j).bssid.tostring(); data[j].lvl = wifilist1.get(j).level; data[j].count++; }
if tell me why showing null pointer exception @
data[j].ssid = wifilist1.get(j).ssid.tostring();
problem scan_data array not initialized objects.
scan_data[] data = new scan_data[k];
this initializing array not putting objects in it. have explicitly in loop. create scan_data object , put values in , put on data[j].
(int j=0;j<l;j++){ scan_data sdata = new scan_data(); // set desired values in sdata scandata data[j] = sdata; }
hope helps.
Comments
Post a Comment