小编use*_*471的帖子

ListView的NullPointerException

我在第29行(private ListView lv = (ListView) findViewById(R.id.ScanList);)获得了NPE ,但我想这是因为以下行:

this.adapter = new SimpleAdapter(ScannerActivity.this, arraylist, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value });
Run Code Online (Sandbox Code Playgroud)

什么属于"R.id.list_value"和"R.layout.row"它是一个row.xml?我不知道我在那里写的东西!

要知道代码是如何工作的,我粘贴一个relvant部分:

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;

/* …
Run Code Online (Sandbox Code Playgroud)

android listview exception

0
推荐指数
1
解决办法
141
查看次数

标签 统计

android ×1

exception ×1

listview ×1