0

Actually my MainActivity has four fragments. And i am trying to play the animation on 1st fragment of MainActivity the error is :

" Attempt to invoke virtual method 'void android.widget.TextView.startAnimation(android.view.animation.Animation)' on a null object reference"

below is my code :

override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    createFragmentOne()
    nav.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
    nav.setItemIconTintList(null)
    try{
        var sep :TextView?
        sep = findViewById<TextView>(R.id.sepratesection)
        var anim = AnimationUtils.loadAnimation(this,R.anim.blink)
        sep.startAnimation(anim)
    }
    catch (e : Exception)
    {
        e.printStackTrace()
    }

TextView is in First Fragment .

mohammadReza Abiri
  • 1,759
  • 1
  • 9
  • 20

1 Answers1

1

You try this with kotlin so try directly like

sepratesection .startAnimation(anim)