The best way to learn is to solve problem by yourself. Here I'll tell you how to proceed when your app crashes suddenly and you have no idea.
If your application crashes then we'll be looking for " logcat ".
Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class.
For more https://developer.android.com/studio/command-line/logcat.html
c) Next step is to filter our logcat to error mode so that we can see only those message which are related to error. Change your logcat from verbose to error mode and here is your logcat for error.
Great!! now you know how to open logcat. Now let's learn how to use it.
Let's take an example and with the same concept you can solve any problem. The Below program converts two string numbers into integers, calculates the sum and prints the result in TextView as you can see the layout.xml below.. but to learn how to use logcat I have made mistake in this code..Let's resolve the error by seeing the logcat.
But when we run the program, our program will crash so we'll open the logcat as we're told above.[Note : If you're using external device to run the app then it must remain conntectd to your android studio].The logcat for above example looks like :-
We will look only for the highlighted lines in logcat...we can see that logcat specifies error like "NumbeFormatException"...and also we see ' Invalid int: "abc" ' ,with a error of "NumbeFormatException" and ' Invalid int: "abc" ' we can guess that error is related to NumberConversion and also there is something wrong with int ...and you can see that these error occur in the Mainactivity.java by looking the path in the first line. So, we'll move back to MainActivity.java
Now, we'll look our Mainactivity.java. Here you see that, we're not taking integers string for s1 so while parsing that string into integers, it creates error.
Tip :- Sometimes your logcat might not be easy to understand, or can more complex as compared to this example and you might not have any idea about the error, so in that case just copy the highlighted lines of your logcat and paste on google and in many cases you will get your solution on stack-overflow
- FlyingKripto -Github