29 行目 ( ) で NPE が表示されますが、private ListView lv = (ListView) findViewById(R.id.ScanList);
これは次の行が原因であると推測されます。
this.adapter = new SimpleAdapter(ScannerActivity.this, arraylist, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value });
「R.id.list_value」と「R.layout.row」に属するものはrow.xmlですか? そこに書かなければならないことがわかりません!
コードがどのように機能するかを知るために、関連する部分を貼り付けます。
public class ScannerActivity extends Activity implements OnClickListener {
private WifiManager wifi;
private ListView lv = (ListView) findViewById(R.id.ScanList);
private Button buttonScan = (Button) findViewById(R.id.scannow_button);
private Switch enable;
private int size = 0;
private List<ScanResult> results;
private final String ITEM_KEY = "key";
private final ArrayList<HashMap<String, String>> arraylist = new ArrayList<HashMap<String, String>>();
private SimpleAdapter adapter;
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
buttonScan.setOnClickListener(this);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
enable.setChecked(wifi.isWifiEnabled());
enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
wifi.setWifiEnabled(flag);
if (flag) {
arraylist.clear();
lv.setVisibility(View.VISIBLE);
buttonScan.setEnabled(true);
wifi.startScan();
} else {
lv.setVisibility(View.INVISIBLE);
buttonScan.setEnabled(false);
}
}
});
this.adapter = new SimpleAdapter(ScannerActivity.this, arraylist, R.layout.activity_scan, new String[]{ITEM_KEY}, new int[]{R.id.ScanList});
lv.setAdapter(this.adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long id) {
lv.getSelectedItemPosition();
Intent myIntent = new Intent(ScannerActivity.this, MyActivity.class);
String mac = results.get(size).BSSID;
myIntent.putExtra("mac", mac);
ScannerActivity.this.startActivity(myIntent);
}
});
これは私の最初のListViewなので、助けてください:)