user123321
user123321

Reputation: 12783

Android Stack Trace - Where is error shown?

Why can't I see the method that throws the runtime exception in Android? Or is it there and I don't understand how to read the stack trace? In Flash, it's easy to see where the error is thrown. In Android, it not easy. Maybe because it throws in a different thread. I have no idea. Attached are the sceens. Can you see where the error is thrown in the stack trace?

enter image description here

enter image description here

Upvotes: 2

Views: 1887

Answers (3)

user123321
user123321

Reputation: 12783

Debug stacktrace mode does not show it. Logcat may.

Upvotes: 0

JasCav
JasCav

Reputation: 34632

The issue is that you haven't let the stack trace "unroll" out enough yet. When the exception is thrown, you have to keep stepping through until you see the exception appearing within LogCat (which you should be able to see in the default Debug View).

For example, here is my code:

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        throw new RuntimeException("Exception");
        //setContentView(R.layout.main);
    }
}

When the exception is finally thrown all the way up the stack, I will finally see this within my LogCat window:

enter image description here

If you look here, you can see at the top of the stack trace, the thrown exception. However, this doesn't tell you a whole lot (except what happened). Towards the bottom of the LogCat window, you can see what the actual cause was from (which you'll see once the entire exception unrolls). In this particular case, it occurred in my HelloAndroid.onCreate() method (which I have selected). When you double-click on this line, you will be taken to your code and where the exception actually occurred.

Upvotes: 4

gian1200
gian1200

Reputation: 3854

I've never used debug mode but I use the LogCat View. You activate it in

Window --> Show View --> Other --> Android --> LogCat.

If an exception is thrown, the log show it in red. In my experience, the real problem never appear at the beginning of the exception, it appears after the line

"Caused By"

There you will see in which line in your code the exception was generated and be able to go there by simply double clicking it.

Upvotes: 1

Related Questions