Android 报错:Attempt to invoke virtual method...on a null object reference

Android Studio运行程序时,报以下错误:

Attempt to invoke virtual method ‘void android.widget.ListView.setOnItemClickListener
(android.widget.AdapterView$OnItemClickListener)’ on a null object reference

原因分析:

可能是因为 id 指向错误导致,例如 Button mBtn=findViewById(R.id.btn); 中,btn 一定要指向正确的对应的 xml 文件中的 btn

猜你喜欢

转载自blog.csdn.net/WU2629409421perfect/article/details/104201546