当前位置:网站首页>findViewById返回null的问题
findViewById返回null的问题
2022-08-11 04:30:00 【百口可乐__】
最近刚接触android编程,使用listview发现程序运行崩溃闪退,发现是findViewById返回了null值
查找错误原来是
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
setContentView(R.layout.activity_main);被我注释掉了!!导致在加载视图之前使用findViewById寻找控件id!访问视图没有加载出来控件id是找不到的
findViewById要写在setContentView后面
setContentView(R.layout.activity_main);
ListView listView = (ListView)findViewById(R.id.lv);
边栏推荐
- Common layout effect realization scheme
- LeetCode刷题第16天之《239滑动窗口最大值》
- What are port 80 and port 443?What's the difference?
- Which one to choose for mobile map development?
- [Note] Is the value of BatchSize the bigger the better?
- [Actual combat scene] Mall-discount event design plan
- "104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
- Provincial level of Echart maps, as well as all prefecture-level download and use
- 获取Qt的安装信息:包括安装目录及各种宏地址
- How to learn machine learning?machine learning process
猜你喜欢
UNI-APP_iphone bottom safe area
干货:服务器网卡组技术原理与实践
【人话版】WEB3将至之“权益的游戏”
(转)JVM中那些区域会发生OOM?
leetcode刷题第13天二叉树系列之《98 BST及其验证》
Interchangeable Measurement Techniques - Geometric Errors
自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告
[FPGA] day19- binary to decimal (BCD code)
LeetCode刷题第17天之《3 无重复字符的最长子串》
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
随机推荐
Multi-serial port RS485 industrial gateway BL110
机器学习可以应用在哪些场景?机器学习有什么用?
Add PRODUCT_BOOT_JARS and classes to provide jar packages to applications
MySQL database storage engine and database creation, modification and deletion
【ImageNet】数据集1000个类的名称
.NET Custom Middleware
How to learn machine learning?machine learning process
[FPGA] day19- binary to decimal (BCD code)
Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
Mysql: set the primary key to automatically increase the starting value
What is machine learning?Explain machine learning concepts in detail
洛谷P4847 银河英雄传说V2
.NET 服务注册
破解事务性工作瓶颈,君子签电子合同释放HR“源动力”!
优先级队列
.NET自定义中间件
[FPGA] Design Ideas - I2C Protocol
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
Harvesting of radio frequency energy
堆排序 和冒泡排序