I have a Cordova app that compiles with no errors. However, when I lunch the app to my android device it instantly crashes on startup. I am having a hard time debugging when I do not know what the bug is…
QUESTION: Is there a way to get the error report from this crash?
I usually use chrome to debug my app but that only works if the app is able to load and run on the device.
You requested some article about logcat... I'm putting in the answer section since it is too much information for comments :)
DOCS
In case of Android, you can always go to Developer's page.
HERE is the Android's page about logcat
If you use android Studio, you can also check this LINK.
Capturing
Basically, you can capture logcat with following command:
adb logcat
There's a lot of parameters you can add to command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:
adb logcat -v time
You can redirect the output to a file and analyze it in a Text Editor.
Analyzing
If you app is Crashing, you'll get something like:
07-09 08:29:13.474 21144-21144/com.example.khan.abc D/AndroidRuntime: Shutting down VM
07-09 08:29:13.475 21144-21144/com.example.khan.abc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.khan.abc, PID: 21144
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20262)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-09 08:29:15.195 21144-21144/com.example.khan.abc I/Process: Sending signal. PID: 21144 SIG: 9
This part of the log shows you a lot of information:
07-09 08:29:13.475
It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)
com.example.khan.abc
This way, you know which app crashed (to be sure that you are checking the logs about your message)
java.lang.NullPointerException
A NULL Pointer Exception error
Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
You tried to call method onBackPressed()
from a FragmentActivity
object. However, that object was null
when you did it.
Stack Trace: Stack Trace shows you the method invocation order... Sometimes, the error happens in the calling method (and not in the called method).
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
Error happened in file com.example.khan.abc.AudioFragment.java
, inside onClick()
method at line: 125
(stacktrace shows the line that error happened)
It was called by:
at android.view.View.performClick(View.java:4848)
Which was called by:
at android.view.View$PerformClick.run(View.java:20262)
which was called by:
at android.os.Handler.handleCallback(Handler.java:815)
etc....
Overview
This was just an overview... Not all logs are simple etc... It is just to share the idea and provide a entry-level information to you...
I hope I could help you someway... Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With