why my app is crushing after passing the seconds ?

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

            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() {

                            public void onClick(DialogInterface dialog, int which) {

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

Recommended Answers

All 5 Replies

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, learning, and sharing knowledge.