android - 错误 java.lang.IllegalStateException:other 不能为空
问题描述
我是 Android 开发的新手,我提供了我的代码片段。我想知道为什么它说other must not be null
other = findViewById(R.id.otherId)
我的活动:
class SplashScreen : AppCompatActivity() {
lateinit var topAnimation:Animation
lateinit var bottomAnimation:Animation
lateinit var logoImage:ImageView
lateinit var bangerText:TextView
override fun onCreate(savedInstanceState: Bundle?) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
topAnimation=AnimationUtils.loadAnimation(this,R.anim.top_animation)
bottomAnimation=AnimationUtils.loadAnimation(this,R.anim.bottom_animation)
logoImage=findViewById(R.id.logoImage)
bangerText=findViewById(R.id.bangerTextView)
val other=findViewById<TextView>(R.id.textView5)
logoImage.animation=topAnimation
bangerText.animation=bottomAnimation
other.animation=bottomAnimation
}
}
解决方案
你能检查一下 layout/activity_splash_screen.xml 是否真的有 id/textView5 吗?
如果该布局中未指定该 ID,则 findViewById 可能会返回 null
推荐阅读
- python - Pandas 未安装在 Ubuntu 中
- powershell - 如何使用 PowerShell 不断更新映射文件的路径文件夹?
- php - 如何创建产品详细信息页面?
- excel - 在 VBA 中,使用 With、End With 总是更好吗?
- java - 如何升级此正则表达式而不捕获“1hey”或“123_456_bye”或“1123_hey”
- php - 如何将配置文件包含到类中?
- encryption - KeyCloak 用户凭证加密
- python - Python:如何将数组分成块
- ios - 从firestore查询数据时,如何将保存的字符串格式的日期与当前日期进行比较?
- java - 非 void java 函数中的“返回 a|b|c”是什么意思?