I have a game that adds a point every time a player passes a ball through a goal. I added a TextView that I want updated every time a goal and initialized it with the text "1" and gave it the id "scoreTextView". I tried to declare a TextView variable in my main activity and using addView but my game crashes everytime.I have also tried passing in Layout params along with the TextView to be displayed after reading another StackOverflow question but that also caused my game to crash. When I dont declare a TextView varible and dont add the scoreTextView to the mainView (that is the name of my FrameLayout varible) in my main activity the game actually runs and displays the 1 but if I can't access the scoreTextView from my activity I have no way to change it. So my question is how do I create a TextView in a FrameLayout that I actually can use and change dynamically as needed in my main activity?
I have already looked at this and tried it but they didn't work: Add a Textview to a FrameLayout in a determined position