0

While developing Android application, from time to time I face a situation when an exception occures, but can not be traced down through a stack, because the stack which is shown at such moments mentions only system methods, and not any of my code lines. For example, if I erroneusly pass an incorrect string to Float.parseFloat, I got something like this:

Thread [<1> main] (Suspended)   
LoadedApk$ReceiverDispatcher$Args.run() line: 710   
ActivityThread$H(Handler).handleCallback(Message) line: 587 
ActivityThread$H(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 3729    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 874  
ZygoteInit.main(String[]) line: 632 
NativeStart.main(String[]) line: not available [native method]  

and this:

Thread [<1> main] (Suspended (exception RuntimeException))  
LoadedApk$ReceiverDispatcher$Args.run() line: 722   
ActivityThread$H(Handler).handleCallback(Message) line: 587 
ActivityThread$H(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 3729    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 874  
ZygoteInit.main(String[]) line: 632 
NativeStart.main(String[]) line: not available [native method]  

The question is - how can I pinpoint a line of my code, which causes the problem? In the case of incorrect parseFloat usage, I'd expect to see a mention of parseFloat in the stack and my methods which contain the invocation.

2
  • If you pass a wrong argument to a system function, one of the lines in the stack trace should be your call, pointing to your file. Commented Apr 19, 2012 at 16:48
  • I am having the same issue, were you able to solve it? Commented Dec 12, 2012 at 22:50

1 Answer 1

1

Check Logcat in the DDMS view in eclipse. That will show you a better stacktrace of where exactly in your code the error is thrown and what the error is

Ex. I wrote a test app that uses Float.parseFloat invalidly like you said and get the following error in logcat

04-19 12:56:55.929: E/AndroidRuntime(8532): FATAL EXCEPTION: main
04-19 12:56:55.929: E/AndroidRuntime(8532): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.testing/com.test.testing.TestingActivity}: java.lang.NumberFormatException
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.os.Looper.loop(Looper.java:130)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread.main(ActivityThread.java:3835)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at java.lang.reflect.Method.invoke(Method.java:507)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at dalvik.system.NativeStart.main(Native Method)
04-19 12:56:55.929: E/AndroidRuntime(8532): Caused by: java.lang.NumberFormatException
04-19 12:56:55.929: E/AndroidRuntime(8532):     at org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:321)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at java.lang.Float.parseFloat(Float.java:323)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at com.test.testing.TestingActivity.onCreate(TestingActivity.java:15)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-19 12:56:55.929: E/AndroidRuntime(8532):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-19 12:56:55.929: E/AndroidRuntime(8532):     ... 11 more

We see the error is caused by java.lang.NumberFormatException and drilling down we see it comes from here:

at com.test.testing.TestingActivity.onCreate(TestingActivity.java:15)

It points to my activity in the method onCreate on line #15. If i look at line 15 I see Float.parseFloat("bacon"); and find my problem. We can't parse bacon as a float (Although that may be delicious) so it throws the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.