Android 开发中出现java.lang.NullPointerException

来源:互联网 发布:科目一挂机软件 编辑:程序博客网 时间:2024/05/18 15:50

android 中出现这种错误的机会有很多,本人这次出现的 原因是:
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popView = inflater.inflate(R.layout.popup_layout, null);
popupWindow = new PopupWindow(popView,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);

popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
gridView = (GridView)findViewById(R.id.gridView1);

gridView.setOnItemClickListener(new ItemClickListener());


这其中 gridView = (GridView)findViewById(R.id.gridView1);

应该是gridView = (GridView)popView.findViewById(R.id.gridView1);

就是网格组件在popView这个xml文件中,必须加上去

0 0
原创粉丝点击