1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
我注意到下面評(píng)論中提到的一個(gè)主要問(wèn)題。
public class SecondActivity extends AppCompatActivity {
private ListView lvContact;
private Button addBtn,dleBtn;
private PersonListAdapter adapter;
private List<Person> mPersonList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);
//Error as creating a new object mPersonList which is local to onCreate()
//Finally class variable mPersonList will be null still.
//ArrayList<Person> mPersonList = new ArrayList<Person>(); //Logical Error
//Solution: Use class variable instead of creating a new variable. So, just replace the above commented line with below one.
mPersonList = new ArrayList<Person>();
addBtn = (Button) findViewById(R.id.update);
..... continue
}
希望它能解決您的問(wèn)題。
添加回答
舉報(bào)