首页上一页 1 下一页尾页 1 条记录 1/1页
下拉列表框报错
发表在Android图书答疑
2019-10-09
《零基础学Android》第4章 常用UI组件
是否精华
是
否
版块置顶:
是
否
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Spinner sp = findViewById(R.id.mSpinner); String[] ctype = {"全部","歌曲","小说","游戏","直播","活动","图书"}; ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, ctype); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp.setAdapter(arrayAdapter); //25 }
报错 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference at com.example.demo04.MainActivity.onCreate(MainActivity.java:25)