我有2節課。一個類在我的擴展視圖的 GameView 類中創建了我的迷宮游戲。GameView 類:將我的視圖的可見性設置為 VISIBLE,直到玩家 == 退出,然后它不可見(如預期的那樣)但是我的 LinearLayout 視圖(在 OnCreate、MainActivity.java 中是不可見的)當布爾值(播放器)設置為 VISIBLE == exit) 為真,導致應用程序崩潰。我知道更改 LinearLayout 的可見性會導致崩潰,就好像我將其注釋掉一樣,它會使應用程序崩潰。我試圖更改我的 MainActivity 類中的可見性,但這似乎也不起作用。我目前正在嘗試使用 Intent 將此信息推送到 MainActivity,以使用我的 playAgain() 但我不確定該怎么做。@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout layout = findViewById(R.id.playAgainLayout); layout.setVisibility(View.INVISIBLE);}public void createMaze(){...... do { next = getNeighbour(current); if (next != null) { removeWall(current, next); stack.push(current); current = next; current.visited = true; } else current = stack.pop(); //gives us the top element of the stack and removes it from the }while(!stack.empty()); Animation slideUp = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up); gameView.startAnimation(slideUp);}public void checkExit() { if (player == exit && counter < 3) { counter++; Animation slideDown = AnimationUtils.loadAnimation(getContext(), R.anim.mazeslidedown); gameView.startAnimation(slideDown); gameView.setVisibility(INVISIBLE);// layout.setVisibility(VISIBLE); } }我想要的是讓迷宮變得不可見,LinearLayout 變得可見,并允許用戶點擊我的按鈕(暫時重新啟動迷宮)。
更改可見性導致我的應用程序崩潰,為什么?
慕桂英4014372
2023-03-17 14:15:15