![](/img/trans.png)
[英]Why List<String> is always empty when using MapReduce and HDFS?
[英]Why the list is always empty?
在這段代碼中,我正在搜索wifi接入點並在文本視圖中顯示結果。...在三星手機上工作正常,但由於某些原因,如果使用其他手機,則列表始終為空。
您能幫助我了解為什么列表始終為空嗎? 我將不勝感激。
public class MainActivity extends AppCompatActivity {
Switch aswitch;
int n=1;
TextView text;
WifiManager wifi;
String message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aswitch=(Switch)findViewById(R.id.myswitch);
wifi=(WifiManager)getSystemService(WIFI_SERVICE);
text=(TextView)findViewById(R.id.mytv);
aswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// do something, the isChecked will be
// true if the switch is in the On position
if (isChecked && !wifi.isWifiEnabled()) {
wifi.setWifiEnabled(true);
message="enabled";
text.setText(message);
} else if (!isChecked && wifi.isWifiEnabled()){
wifi.setWifiEnabled(false);
message="disabled";
text.setText(message);
}
}
});
MyBroadcastReceiver broadcast=new MyBroadcastReceiver();
registerReceiver(broadcast, new IntentFilter(wifi.SCAN_RESULTS_AVAILABLE_ACTION));
}
class MyBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
StringBuffer stringBuffer=new StringBuffer();
List<ScanResult> list=wifi.getScanResults();
for(ScanResult scanResult:list){
String ssid0 = scanResult.SSID;
int rssi0 = scanResult.level;
String rssiString0 = String.valueOf(rssi0);
stringBuffer.append("\n SSID:" + ssid0 + " RSSI:" + rssiString0 +"dBm");
text.setText("yes");
}
text.setText(stringBuffer);
if(wifi.isWifiEnabled()){
wifi.startScan();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
看起來很奇怪,您必須在清單中聲明精細或粗略的位置許可。 我前一段時間有這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.