3

I've just started learning how to develop applications for Android. Currently, I am using Eclipse 4.2 (Juno) as the IDE. The problem is I can't see a normal way to view exceptions that are happening in my own code. For example:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    List<BasicObject> objects = _objectRepository.GetAllObjects();
    Iterator<BasicObject> iterator = objects.iterator();

    while(iterator.hasNext())
    {
        ObjectListItemView itemView= new ObjectListItemView(this,iterator.next());
    }
}

At the time when onCreate is running, _objectRepository is null and so the NullReference is thrown. After that Eclipse displays "Source not found", which is really not what I expect. Then I press F8 (continue) multiple times; the process exits and the debugger stops. And only after that can I see some stacktrace in LogCat (from where it's really hard to navigate to my own code).

As you can see, all this process of catching exceptions is really time-consuming. Is there any other way to view exceptions and what am I doing wrong?

I am not using an Android emulator, I am using a real device (HTC Desire S). I already have LogCat, but I'd like something more handy/practical.

To illustrate, in Visual Studio I can see an exception while debugging. Visual Studio sets a break on the line where the exception occurred and I can view any information I want (stack trace local variables, all stuff actually) in the exception window (see The {not much utilized} Debug->Exceptions… window technique).

In Eclipse I got exception details in LogCat (which is very uncomfortable to use) and only after the debugger is stopped.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
armless-coder
  • 95
  • 1
  • 9
  • I presume by "with VS" you don't mean android in VS? Logcat is part of android, eclipse just provdies a view of it (you can see the same thing in a terminal window without any IDE). – CodeClown42 Aug 11 '12 at 11:42
  • Sorry cant find where i wrote "with VS". I am not developing android app in VS, i am using Eclipse. – armless-coder Aug 11 '12 at 11:50
  • Actually it was "For example in visual studio"; what I meant was the delay in the logcat reporting is not a normal eclipse thing either. It's specific to logcat and android and (I presume) would be the same in VS. The exception triggers the debugger before the exception is reported to logcat, which is why you have to resume to see it reported there. – CodeClown42 Aug 11 '12 at 11:54

2 Answers2

1

You can enable LogCat for Android like this:

In Eclipse, go to Window -> Show View -> Other -> Android -> Logcat.

Logcat is nothing but a console of your emulator or device.

How to enable logcat/Console in Eclipse for Android?

Community
  • 1
  • 1
UVM
  • 9,776
  • 6
  • 41
  • 66
  • I think armless-coder already has logcat in eclipse, that's not the issue. – CodeClown42 Aug 11 '12 at 11:19
  • @goldilocks, he is finding difficulty in viewing exceptions in android emulator while debugging.But if he is running application in normal code, he can see all exceptions throwing exceptions from applications in logcat.In either way, logcat is the one where all exceptions can be visible. – UVM Aug 11 '12 at 11:24
  • UVM: Yes, but s/he is already referring to seeing the exceptions in logcat but is confused about how they get there ("only after that i can see some stacktrace in logcat"). Nb. logcat is identical inside or outside of eclipse. – CodeClown42 Aug 11 '12 at 11:28
  • He says that due to Null, a nullpointer exception is thrown.It is a runtimeexception.A runtimeexception can be viewed in logcat.But what I understand is that there some pieces of code in java where exceptions are silently consumed.So in that case, it will not be even visible in logcat either.So need to understand more about his code. – UVM Aug 11 '12 at 11:34
  • Thx, i already got a logcat and i can see stacktrace in it, but only after i stop a debugger. – armless-coder Aug 11 '12 at 11:35
  • @armless-coder: pretty sure it is for the reasons mentioned in my answer. I don't think there is any way out of that: it's the Android OS that is responsible, not eclipse, so it doesn't matter what tool you use. Remember, you are debugging code that is running on a seperate machine. – CodeClown42 Aug 11 '12 at 11:39
-1

The OS has to do a few things in order to get a message to logcat; these are triggered by the (uncaught) exception. If you try to step through them in the debugger it is tedious and you get "Source not found" a lot (that's system code, not yours).

Irritating, but it is a safe bet that whatever happens after the exception does not happen inside your app, so you might as well stop at that point anyway. If you need to see the logcat report of an exception quickly, just run the app without the debugger.

CodeClown42
  • 11,194
  • 1
  • 32
  • 67