猿问

java.lang.NullPointerException:尝试在空对象引用上调用接口方法

java.lang.NullPointerException:尝试在空对象引用上调用接口方法“boolean java.util.List.add(java.lang.Object)”

我需要对主 XML 的每个编辑文本进行验证并且保存按钮也在滚动并且日期显示在日期的文本视图中,保存后应该将人员详细信息添加到列表视图顶部的下一个屏幕,已经是列表视图有五个默认的人员详细信息,我无法执行此操作,请帮助我,在列表视图中,每个项目都应包含更新和删除按钮,单击更新 dailog 应打开并需要在 dailog 中进行编辑,删除意味着从列表视图中删除人员详细信息.

activity_main.xml


神不在的星期二
浏览 154回答 1
1回答

繁华开满天机

我注意到下面评论中提到的一个主要问题。&nbsp; &nbsp; public class SecondActivity extends AppCompatActivity {&nbsp; &nbsp; private ListView lvContact;&nbsp; &nbsp; private Button addBtn,dleBtn;&nbsp; &nbsp; private PersonListAdapter adapter;&nbsp; &nbsp; private List<Person> mPersonList;&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void onCreate(Bundle savedInstanceState) {&nbsp; &nbsp; &nbsp; &nbsp; super.onCreate(savedInstanceState);&nbsp; &nbsp; &nbsp; &nbsp; setContentView(R.layout.second_layout);&nbsp; &nbsp; &nbsp; &nbsp; //Error as creating a new object mPersonList which is local to onCreate()&nbsp; &nbsp; &nbsp; &nbsp; //Finally class variable mPersonList will be null still.&nbsp; &nbsp; &nbsp; &nbsp; //ArrayList<Person> mPersonList = new ArrayList<Person>(); //Logical Error&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //Solution: Use class variable instead of creating a new variable. So, just replace the above commented line with below one.&nbsp; &nbsp; &nbsp; &nbsp; mPersonList = new ArrayList<Person>();&nbsp; &nbsp; &nbsp; &nbsp; addBtn = (Button) findViewById(R.id.update);&nbsp; &nbsp; &nbsp; &nbsp; ..... continue&nbsp; &nbsp; }希望它能解决您的问题。
随时随地看视频慕课网APP

相关分类

Java
我要回答