此代码发出错误消息“错误接收活动中的广播意图” 虽然我找不到任何想法,但是我找不到任何想法? 我已经将循环条件添加为7,因为我只想要前七个扫描结果
class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context con, Intent intent) {
sb = new StringBuilder();
wifiList = mainWifi.getScanResults();
for(int i = 0; i < wifiList.size(); i++)
{
sb.append((wifiList.get(i)).SSID.toString());
sb.append(' ');
sb.append('!');
sb.append("\n\n");
}
String net = sb.toString();
if(wifiList.size() > 0)
{
char excl = '!';
int excl1 = excl;
String[] aray = null;
for(int j = 0; j<7; j++)
{
int index = net.indexOf(excl1);
String a = net.substring(0, index);
aray[j] = a;
String temp = net.substring(index+1);
net = temp;
}
String one = aray[0];
String two = aray[1];
String three = aray[2];
String four = aray[3];
String five = aray[4];
String six = aray[5];
String seven = aray[7];
tv1.setText(one);
}
else
{
tv1.setText("No Networks Detected");
}
}
}
PS:我只添加到一个TextView中,因为这是一个测试模块
答案 0 :(得分:0)
“aray”数组未正确初始化。您需要在访问之前初始化“aray”:
String[] aray = new String[7];
你也超出了数组的维度。这样:
String seven = aray[7];
应该是:
String seven = aray[6];
更好的解决方案是使用ArrayList。
ArrayList al = new ArrayList();
al.add(yourString);