How to know which line the app crashed? - android

I'm debugging an app in a real device and Eclipse. Certain feature makes it crash. There is no error on LogCat. I've managed to find which line it crashed in a similar situation by writting Log.v in many lines until I found which Log.v didn't show up. Isn't there a better solution?

You could use the Debugging feature in Eclipse - it allows you to break the program flow on the occurrence of an exception (Run As -> Debug).
This will allow you to inspect the current local variables / call stack to further diagnose why the exception occurs.
p.s. One other method I use when hunting down an odd crash is to dump the full LogCat via the 'adb' CLI tool, and inspect it in a text editor. Sometimes the LogCat display in Eclipse can go a bit.. weird..especially if you've been connecting / disconnecting your device while developing (without closing Eclipse)

Check Logcat filters (in Eclipse). Happens to me.

I was using the 'debug' option on Eclipse, which made it not show the error. Detaching the debug after the crash, or just running the application from the begin (without the debug options) shows the error. To find the line, filter your LogCat by application, make the app crash and, on the red text that will appear, look for your package name. And the of the error (expection) itself is on the beginning of that text.

Related

Android Studio, logcat cleans after app closes

I'm having a problem with my logcat since update 1.2 Beta for Android Studio. When I run my app it logs everything like it normally did, then I get at the point where my app crashes with the app saying: unfortunately, Game has stopped.
After a few seconds android closes that message. When that happens my logcat also gets fully cleared meaning that I barely get anytime to read the error. I did found some info about a buffer, but it seems that Android Studio doesn't have the option to increase it besides the fact that I doubt that being the problem.
Something that may be useful is that after it clears and stuff the process changes to Android.process.core and the message I get in my logcat is:
04-13 10:28:13.394 12259-12265/android.process.acore D/dalvikvm﹕
Debugger has detached; object registry had 1 entries
Edit: I did read about breakpoints, so disabled focus application on breakpoints in Settings-build, execution, deployment-debugger but it didn't have any effect.
I had the same issue, but looks more like a feature than a bug:
In AndroidStudio, the default setting for the Logcat window seems to be "Show only selected Application" (top right corner of the Logcat window)... which is looking at the log of the selected process (your current launch by default). So when your app crashes during testing, that process is gone, so the filter clears the log.
Instead, select "Edit Filter Configuration..." and set up a filter for your app, eg:
FilterName: MyApp
PackageName: com.example.myapp (<< replace with your app's package name)
...and then select that filter for future runs. This should keep the log there for you, even after the app crashes.
Switch "Show only selected application" to "No filters". This way, you can see logcat output from a process even when that process isn't running.
The downside is that your logcat will be filled with more spam from other processes.
In case of crash see the Run tab at the bottom of IDE.
You can see the crash reason in this part (even in logcat clean case).
Note: If the above trick not works try to produce a crash and immediately disconnect the mobile cable (if you use the real device for the test). you can see the error before it cleaned.
Update: If also above trick not works, try to attach and detach phone and hopefully problem solved.
Update2: If again not work, try to Invalidate catches and Restart then start debugging again.
Update3: As The last way, try to remove the app and install it again then start debugging (if you do not lose that condition you want to test)
My App was crashing and restarting. I also had some problems on reading the logcat to know what was happening. I then noticed that in the drop down menu, next to the Device dropdown it had something like "com.mypackage.myapp ('some number')" and when my app crashed there was another option that said "com.mypackage.myapp ('some number') [DEAD]". If you select the "Dead" option, it will show you the logcat of the previous instance.
Might be very late to the party but I had the same problem and solved like this:
In logcat window, top right corner drop-down menu select Edit filter configuration, on the next menu, introduce Filter name and your Package name.
Done, for me it keeps logs visible after crashing.
In Android Studio 2+
Click Run
Click Edit Configurations
In the Run/Debug Configurations window select the Miscellaneous tab
Make sure the Clear log before launch checkbox is not checked
The filter clears the log once the app gets crashed. So select "Edit Filter Configuration" and create your own custom filter with filter name. This will save the log with informations even when the app is crahed.
I'm Working with Android Studio 4.0
enter image description here
Go to Edit Configuration of your app.
Go to Miscellaneous Tab
Uncheck the field Clear log before launch.
Press OK.
It'll work..
i have faced the same issue and this is the solution :-
1- Tools --> Android --> Enable ADB Integration.
and now you can see the logcat and the crashes as normal
It is 2018 and this can still happen. Close Android Studio and reopen.
7 years later ...
I still have same issue on AS ArcticFox and nothing helps.
But I have found one workaround.
make sure this is enabled:
Then you can see your logs regardless the app is alive or not or device is connected or not. Which is great!
Still, sometimes I get this problem although some solutions work here such as restarting android studio it takes time.
Here I found how to get error message without restarting the studio
Launch the app
Be on run tab before you make your reproduce crash
Click on the content of run tab as soon as crash occurs (if you don't click on content you will lose error report)
This bug seems to be fixed with the new release of Android Studio version 1.2.2
I ran into the same problem and none of the answers could help me, until I realized my app was causing an OutOfMemoryException. That's a probable root cause as well.

Genymotion doesnt show mistakes

I'm having hard time to find answer in Google to this stupid question.
I come from C# to android development and in C# when my application crush, the compiler shows where exactly my application crush in the code and I can see the values of all the variables.
For now, my app crush and I got no idea where to search the mistake.
Is this possible to have in android Eclipse with GenyMotion emulator this behavior? How?
There is a logging facility on Android called LogCat. You can open it in Eclipse by going to menu Window > Show View > Other... > LogCat.
Any uncaught exceptions will be printed in red color. The filter for your application will be created when you run it.
Is this pissibol to have in android Eclipce with genymotion emulator this behavior? How?
To fix your crash first look at the exception in the logcat then try to understand what exactly that error message. For example : NullPointerException then probably you are trying to access which you haven't initialized.
Now to see variable then use debug feature of the IDE. In eclipse with Genymotion or device you can debug your application then use Ctrl + F6 to trace line by line.

No source attachment error when debugging Android applications

I have just started doing Android development on Mac OS X in Eclipse. When debugging an Activity, I keep getting the following errors:
The JAR file /platforms/android-10/android.jar has no source attachment.
This is starting to get very annoying, does it mean something is throwing an exception somewhere? (the message itself does not give any meaningful information as to why this is happening) I do not want to step into the source; does Eclipse do this by default? How do I disable it?
It looks like you have some error in your application. And Android subsystem throws exception. Normally, if such exception originates from android, you'll see this behavior.
What you should do:
Turn on LogCat view to see logs.
Launch your app without debugger (Ctrl+F11 on ubuntu/windows)
Inspect those logs in LogCat very carefully. They will contain the place where exception happened (originating from your code). You will then easily be able to fix the issue yourself (or ask for more assistance if needed).
In a normal development workflow you shouldn't hit cases like yours too often. Its just the learning curve :) So stay calm and keep learning.

How to debug android application using android sdk?

I am new to android application development, I am finding it difficult to debug my program I am always getting some abstract message like "your application stopped working" I need to know exactly. I have read there are many ways to debug. What I need to know is the way which will be easy for beginners like me.
If you are using eclipse (if not you should, is the easiest way to develop/debug for android) take a look at these tutorials, specially the second one (there is a lot more out there if you google a little):
http://www.latenightpc.com/blog/archives/2007/11/21/starting-a-debug-session-for-android-with-adt
the main point you should research about is LogCat and debugger (both covered in the above links)
In eclipse always look at the logCat output in the DDMS or Debug window when the app crashes. Often (buried in the output) is a line telling you exactly what statement (file and line number) caused the crash. Sometimes you need to hit resume (F8) in the Debug window to get the output. Once you get that info you could set a breakpoint at the offending statement and then look at what variable(s) are messed up.

Android - Having a hard time debuging Eclipse

I am a little bit new to developing for Android using Eclipse (Coming from a .NET/Visual Studio background).
My biggest problem in developing Android app is "debugging" them. Every time the emulator throws an error, there is no message, no explanation of what caused the error. I basically have to keep doing trial/error until something works.
My question is: Is there a better way to analyze the error messages that emulator shows (basically some stack trace about Dalvik)!
Also, is it possible in Eclipse [when debugging] to move the debugging cursor backwards to re-evaluate a variable or "skip" some lines of code?
Use LogCat view to see error/debugging messages. Regular console is of very limited help. Window->Show View->Other->Android->LogCat There on the top you will see some round buttons that basically can filter log from V (verbose) to E (error). You can't copy/paste from theLogCat window but you can save selected output to text file
Regarding the error messages (I'm assuming these are the messages that show up in LogCat): I've found that analysing the error messages and working your way up the list until you reach code that is yours is the most effective way to work. Frequently (for me at least) the emulator will crash and break somewhere in the OS code (which you probably don't have the source for) but you can follow the LogCat messages back to your code and start to see where the problem is. The crash may appear to happen in the OS code, but the original cause is typically you passing something wrong to the OS.
Regarding going backwards in code: nope, at least not with the my Eclipse Ganymede install
Regarding skipping code: When your in debug mode under the Run menu you can select "Step Over" (skips going into a method) , "Step Return" to exit a method and "Run to Line" in addition to setting Breakpoints by right clicking. This causes the code to run, but you aren't single stepping through it. Otherwise the only way to "skip" lines of code is to comment it out. I believe you can also change the value of variables in the debugger, but I've never tried personally. This may give you the desired effect.
Try closing all unrelated project, switch off eclipse and then do a clean and build for the project in picture.

Categories

Resources