简体   繁体   English

如何在Eclipse中调试Android时查看异常详细信息?

[英]How to view exception details while debugging Android in Eclipse?

I've just started learning how to develop applications for Android. 我刚刚开始学习如何为Android开发应用程序。 Currently, I am using Eclipse 4.2 (Juno) as the IDE . 目前,我使用Eclipse 4.2 (Juno)作为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. onCreate运行时,_objectRepository为null,因此抛出NullReference。 After that Eclipse displays "Source not found", which is really not what I expect. 之后,Eclipse显示“Source not found”,这实际上不是我所期望的。 Then I press F8 (continue) multiple times; 然后我按F8 (继续)多次; 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). 只有在那之后我才能在LogCat中看到一些堆栈跟踪(从那里很难导航到我自己的代码)。

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 ). 我没有使用Android模拟器,我使用的是真正的设备( HTC Desire S )。 I already have LogCat, but I'd like something more handy/practical. 我已经有了LogCat,但我想要一些更方便/实用的东西。

To illustrate, in Visual Studio I can see an exception while debugging. 为了说明,在Visual Studio中,我可以在调试时看到异常。 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 ). Visual Studio在发生异常的行上设置了一个中断,我可以在异常窗口中查看我想要的任何信息(堆栈跟踪局部变量,实际所有内容)(参见{not much utilization} Debug-> Exceptions ...窗口技术 ) 。

In Eclipse I got exception details in LogCat (which is very uncomfortable to use) and only after the debugger is stopped. 在Eclipse中,我在LogCat中获得了异常细节(使用起来非常不舒服)并且只有在调试器停止后才会出现。

You can enable LogCat for Android like this: 您可以像这样启用LogCat for Android:

In Eclipse, go to Window -> Show View -> Other -> Android -> Logcat . 在Eclipse中,转到Window - > Show View - > Other - > Android - > Logcat

Logcat is nothing but a console of your emulator or device. Logcat只是您的模拟器或设备的控制台。

How to enable logcat/Console in Eclipse for Android? 如何在Eclipse for Android中启用logcat / Console?

The OS has to do a few things in order to get a message to logcat; 操作系统必须做一些事情才能向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. 如果您需要快速查看异常的logcat报告,只需在没有调试器的情况下运行应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM