首页 > 解决方案 > 错误 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
        

    }
}

标签: androidandroid-view

解决方案


你能检查一下 layout/activity_splash_screen.xml 是否真的有 id/textView5 吗?

如果该布局中未指定该 ID,则 findViewById 可能会返回 null


推荐阅读