I am still a beginner at developing Android applications, and I am always encountering Force Closes. When I read the errors in LogCat, I cannot understand what they mean, and even my code is not highlighting the causes for the error. Can you help me please, how can you fix these errors, or how you will know that you have a syntax error, missing arguments, etc.?
Asked
Active
Viewed 144 times
2
-
restart eclipse and run your project and see red color line – Samir Mangroliya May 18 '12 at 16:59
-
The logcat will specify an exception (NullPointerException, NumberFormatException, etc.). Just search the Android documentation for those exceptions, they explain exactly what causes them. Really, most are self-explanatory. You will also see something like `(MyActivity.java:92)` where `MyActivity` is the name of the file behind the cause of the exception, and `92` is the line of code on which the exception is raised. – Kevin Coppock May 18 '12 at 17:00
-
@kcoppock can i ask?how can i see the line numbers in eclipse – jemz May 18 '12 at 17:01
-
@jemz: The line number should be to the left of the lines of code. – Kevin Coppock May 18 '12 at 17:03
-
Try giving us the errors you are getting. The stack trace should also specify the package the error occurred Sometimes the trace shows some of the native calls that are made and results in an error so they are listed first before your code. The first one in this list with your package name (ex: com.mycompany.myapp) is most likely where the error is. – Russ May 18 '12 at 17:05
-
1@jemz From the menu bar, "Window" -> "Preferences..." Under "General" -> "Editors" -> "Text Editors", click the "Show line numbers" checkbox. you can now see numbers – K_Anas May 18 '12 at 17:05
-
@kcoppock, yeah but where is the settings in eclipse so that i can see the line numbers,in default there is no line numbers – jemz May 18 '12 at 17:06
-
05-18 23:50:31.066: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Test.Example/com.Test.Example.Example}: java.lang.NullPointerException – jemz May 18 '12 at 17:06
-
@K_Anas,tenx i see now the line numbers – jemz May 18 '12 at 17:08
-
@Russ,05-18 23:51:31.035: E/AndroidRuntime(585): at android.app.ActivityThread.access$2300(ActivityThread.java:125) – jemz May 18 '12 at 17:08
-
Is that the only line you get? In my experience the 'Unable to start activity' error is usually caused by the activity not being listed in the AndroidManifest.xml – Russ May 18 '12 at 17:10
-
Check this thread out: http://stackoverflow.com/questions/6065258/how-to-interpret-logcat – Kevin Coppock May 18 '12 at 17:12
-
@Russ, 05-19 01:14:06.696: E/AndroidRuntime(964): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) – jemz May 18 '12 at 17:18
1 Answers
1
Jemz there is different exception that can be throwed in your log cat to show you the error in your code: (RuntimeException,NullPointerException,ClassNotFoundException,ClassCastException and many other you will discover when programming android apps :)
Keep in mind that LogCat is your friend and also Internet some times!!
in log cat you see red lines like this for exemple:
01-10 02:10:31.861: E/AndroidRuntime(2216): java.lang.NullPointerException
01-10 02:10:31.861: E/AndroidRuntime(2216): at com.whooznear.android.ServiceServer.serverThreadProc(ServiceServer.java:61)
01-10 02:10:31.861: E/AndroidRuntime(2216):Caused By ....
From these information in the log cat you can get:
You are trying to use a Null object your line of code that causing that exception is line 61 and from the clause caused by you can have an idea about the class responsible on this exception: hope this help to understand a little bit how logcat work

K_Anas
- 31,226
- 9
- 68
- 81