Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old October 20th, 2011, 12:13 PM   #1 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 308
 
Device(s): Samsung Galaxy Nexus
Thanks: 0
Thanked 52 Times in 51 Posts
Lightbulb [TUTORIAL] Use logcat to post problems

I'm reading this forums regularly. And very often, at least once a week there is a person in here asking for help because his app has crashed. Thats fine and all that, but for us to be able to help you, we need to see the exception thrown and if possible the code that produced the exception.

So, how to do this?

1. I'm assuming you already have installed Android SDK and are developing in Eclipse with ADT plugin installed.

2. Launch the app in the emulator or your device(you must have it connected to the computer and the drivers must be installed).

3. When your app crashes, open Eclipse. Go to Window -> Show View -> Other... -> Android -> LogCat

4. The LogCat window will contain alot of information. To reduce the information, click on the green + sign to create a new filter. The only things you need to fill out are: 'Filter name' and 'by log tag' or by 'log level'. If you choose 'by log level' set this to 'error' and click ok.

5. Now you should have only red writing in the window which means you are only viewing the exceptions. Find the start of the exception, it usally starts with: 'FATAL EXCEPTION: main', and the end of the exception which usally ends with: '... x more'. Mark the beginning, hold shitft and mark the end and copy the selected lines by clicking 'Export selected items to text file...'. An exception very often look like this:
Code:
10-20 16:42:08.936: E/AndroidRuntime(339): FATAL EXCEPTION: main
10-20 16:42:08.936: E/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.name/my.package.name.TestActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.os.Looper.loop(Looper.java:123)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at java.lang.reflect.Method.invoke(Method.java:507)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at dalvik.system.NativeStart.main(Native Method)
10-20 16:42:08.936: E/AndroidRuntime(339): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.content.res.Resources.getText(Resources.java:201)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.content.res.Resources.getString(Resources.java:254)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.content.Context.getString(Context.java:183)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at my.package.name.TestActivity.onCreate(TestActivity.java:12)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-20 16:42:08.936: E/AndroidRuntime(339): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-20 16:42:08.936: E/AndroidRuntime(339): 	... 11 more
6. When you now ask for help, paste the content of the exported file, and if possible the code which produced the exception. Where in your code this is is stated in the exception. In the example exception it is stated like this:
Code:
10-20 16:42:08.936: E/AndroidRuntime(339): 	at  my.package.name.TestActivity.onCreate(TestActivity.java:12)
What this tells me is that the exception is beeing thrown in the onCreate method of class TestActivity on line 12.

__________________
Android: Personal Storage, Lars Monsen Facts(Norwegian)
miXer is offline  
Last edited by miXer; October 20th, 2011 at 12:18 PM.
Reply With Quote
Sponsors
Old October 20th, 2011, 12:21 PM   #2 (permalink)
Senior Member
 
TheCompBoy's Avatar
 
Join Date: Oct 2010
Location: Sweden
Posts: 594
 
Device(s): Samsung Galaxy S w DarkyROM v10.1
Thanks: 4
Thanked 56 Times in 51 Posts
Send a message via Skype™ to TheCompBoy
Default

Oh nice.. Hope the people that post their problems will look at this first
__________________
Please check out my blogg: www.thecompboy.blogspot.com
If you want to support me please subscribe / follow the blogg!

OCalc - First App: https://market.android.com/details?id=mendel.calculator.simple&feature=search _result
TheCompBoy is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:08 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo