why my app is crushing after passing the seconds ?

new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                Health -= 1;
                if(Health <= 20) {
                    if (!canSeeWarnDialog) {
                        final AlertDialog alertDialog2 = new AlertDialog.Builder(MainActivity.this).create();
                        alertDialog2.setTitle("Im hungry");
                        alertDialog2.setMessage("The dog health is going low " +
                                "\ngive him some food");
                        alertDialog2.setButton("Got it", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        });
                        alertDialog2.show();
                        canSeeWarnDialog = true;
                        return;
                    }
                }
            }
        }, 0, TimeUnit.SECONDS.toMillis(1));

Anyone ? :S

Do you have a debug or console output/log with the relevant stack trace or error message available for us?

look i need to make every second the health to go down by "1" after going the health under 20 or is equal to 20 to show the "alertDialog" i dont have any errors. The problem is after the "Health" passed the border/limit the application is cryshing i dont know why is that happening, is there someone to help me with it ?
I also make sure that there is one time show of the "alertDialog" with boolean but doesnt help...
Thanks in advice :)

oh god why noone is answering ? :S

ahh cmon guys i need this :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.