Skip to content Skip to sidebar Skip to footer

Unfortunately App Has Stopped Working

I am new to android application development. I was doing this tutorial app.It's a very simple one. It adds one and subtracts one from the counter.When I run it in the emulator ,it

Solution 1:

display= (Button) findViewById(R.id.text);

should be

display= (TextView) findViewById(R.id.text);

Since display is supposed to reference a TextView instance, but you're explictly casting into a Button, and these are not compatible types.

Solution 2:

As you got the answer from A-C this time, but for next time in android application development a important suggestion:

Always see the logcat for error, and see the "Caused by:" tag, It specifies what was the cause of the problem with sufficient detail, Also see the line no that caused that error. And try to find what can be wrong with that line of code.

For example: in your logcat it is showing-

Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button 
at tutorial.example.tutorial.Startingpoint.onCreate(Startingpoint.java:22)

So you can try to read the log, and you will understand that in your file Startingpoint.java at line 22 which is located in onCreate method the error is android.widget.TextView cannot be cast to android.widget.Button. So you can easily remove your errors without any help. Hope that helps not only you current problem but prevented your future time and efforts.

Post a Comment for "Unfortunately App Has Stopped Working"