1

我想用取自(string.xml)和图像的文本填充列表视图。我这样做了,但我得到了 NPE 你能帮我吗?谢谢

public class Menu_activity extends ListActivity {
int[] img = { R.drawable.01, R.drawable.1, R.drawable.2,
        R.drawable.3, R.drawable.4,
        R.drawable.5};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getListView().setDividerHeight(1);
    getListView().setAdapter(new BindDataAdapter(this, img, men));

}
private String[] men = getResources().getStringArray(R.array.men);
4

1 回答 1

2

改成

private String[] men;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    men = getResources().getStringArray(R.array.men); // inside onCreate
    getListView().setDividerHeight(1);
    getListView().setAdapter(new BindDataAdapter(this, img, men));     
}
于 2013-11-09T18:13:20.130 回答