Can't create handler with CountDownTimer class

rollonequick

New Member
I am working a schoolproject where we are making a bomberman game. There are 2 bombermans on the playfield, the User and the AI.When the user places a bomb and walks off it, the bomb flashes and explodes when it's time is over.However this doesn't works with the AI.When the AI places a bomb and walks off it and when it supposed to flash and then explode the app crashes by leaving this error: \[code\]FATAL EXCEPTION: Timer-0 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()\[/code\]The CountDownTimer code is the following.\[code\]public void explodeAIBomb(){ //Starts countdown 2-4 seconds new CountDownTimer(new Random().nextInt(2000) + 2000, 300) { //test for onTick; bomb flashes boolean test = false; public void onFinish() { //on explosion{ gameBoard[locateAIX][locateAIY] = new Blast(); explosionSide(locateAIX, locateAIY); explosionVert(locateAIX, locateAIY); updateView(); //Clear all blasts after 1 second new CountDownTimer(1000, 1000){ public void onFinish(){ for (int x = 0; x < XasLength + 1; x++) { for (int y = 0; y < YasLength + 1; y++) { if(gameBoard[x][y] != null){ if(gameBoard[x][y].getTileId() == BLAST || gameBoard[x][y].getTileId() == BLAST_SIDE || gameBoard[x][y].getTileId() == BLAST_VERT){ gameBoard[x][y] = null; } } } } aiBombPlanted = false; updateView(); } @Override public void onTick(long millisUntilFinished) { } }.start(); updateView(); } //Flashes the bomb every 0.3 second public void onTick(long millisUntilFinished) { if(test){ loadTile(BOMB, r.getDrawable(R.drawable.bomb)); test = false; } else{ loadTile(BOMB, r.getDrawable(R.drawable.bomb2)); test = true; } updateView(); }}.start();\[/code\]}Thanks in advance!
 
Back
Top