看似无用的调试环境为Android [英] Seemingly useless debugging environment for Android

查看:135
本文介绍了看似无用的调试环境为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始调试我的第一个三线较长的Andr​​oid应用程序,我似乎无法使用调试工具,就像我想。 这是我的code:

I've just started debugging my first three line long android app and I can't seem to use the debug tool like I want to. Here's my code:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  int a = 1 / 0;
}

现在我希望调试器停止线程,并告诉我在哪里被零除发生语句的行号。不,相反,它显示了一些的方法内部的制度,我有没有源。为了使事情变得更糟,没有异常的消息无论是。

Now I expect the debugger to halt the thread and show me the line number of statement where the division by zero occurs. No, instead it shows some other method internal to the system for which I have no source. To make the matters worse, there is no exception message either.

在此之前的应用程序,我创建了一个它会做什么时,一个按钮是pressed。如果有任何异常发生,再次将显示任何有用的行号或异常消息。

Prior to this app, I created one which would do something when a button was pressed. If any exception was raised, again no useful line number or exception message would be shown.

截至目前,有没有办法来调试我的应用程序。任何想法?

As of right now, there is no way to debug my app. Any ideas?

我使用的是最新的SDK以及Eclipse的ADT插件和调试的真实设备(的Nexus One)上。

I'm using the latest SDK along with Eclipse ADT plugin and debugging on a real device (Nexus One).

推荐答案

起初,我不得不承认,你是正确的部分。有调试器将停止执行在例外情况,并显示您导致它code线。我很想看到在Eclipse调试此行为。但其他的答案是正确的。

At first I have to admit that you are partially right. There are debuggers that will stop the execution at a exception and show your code line that caused it. I would love to see this behavior in the eclipse debugger. But the other answers are right.

当你在Eclipse中去窗口 - >显示视图 - >其他 - > Android的 - > LogCat中 现在,您将得到所有发生在仿真器或连接的设备调试输出。 有了你,比如我会得到下面的堆栈跟踪。

While you are in Eclipse go to Window -> Show View -> Other -> Android -> LogCat Now you will get all the debugging output that occurs on the emulator or a connected device. With you example I will get the following StackTrace.

T03-18 09:45:12.398: ERROR/AndroidRuntime(1778): Uncaught handler: thread main exiting due to uncaught exception
03-18 09:45:12.428: ERROR/AndroidRuntime(1778): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ClientMain}: java.lang.ArithmeticException: divide by zero
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.os.Looper.loop(Looper.java:123)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.ActivityThread.main(ActivityThread.java:4203)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at java.lang.reflect.Method.invokeNative(Native Method)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at java.lang.reflect.Method.invoke(Method.java:521)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at dalvik.system.NativeStart.main(Native Method)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778): Caused by: java.lang.ArithmeticException: divide by zero
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.client.ClientMain.onCreate(ClientMain.java:35)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     ... 11 more
03-18 09:45:12.438: INFO/Process(52): Sending signal. PID: 1778 SIG: 3

如果你去证明一个提出的所有其他人,你会看到最深的异常

If you go to the deepest Exception shown that one that raised all the others you will see

03-18 09:45:12.428: ERROR/AndroidRuntime(1778): Caused by: java.lang.ArithmeticException: divide by zero
03-18 09:45:12.428: ERROR/AndroidRuntime(1778):     at android.client.ClientMain.onCreate(ClientMain.java:35)

这是pretty的清楚,我想。论ClientMain 35行抛出异常,这是一个被零除例外。如果你不明白这一点(的情况下并不明显的例子),你可以设置该行或方法或某事的切入点一个断点。现在,调试器会告诉你所有的变量,你可以一步,直到出现错误一步执行code步骤。如果你在一个varibale悬停你可以看到这个变量的值,现在你可以一步一步试着去了解异常的原因并解决它。如果你一步深入到code,你会在Java类是负责做的划分,如果你还没有加入的罐子这一类的源$ C ​​$ C到项目调试器ISN结束'T能够显示你的东西在这一点上。

This is pretty clear I think. On line 35 in the ClientMain an Exception was thrown and it was a divide by zero exception. If you can't figure this out (in a case not as clear as the example) you can set a breakpoint on this line or the entry point of the method or something. Now the debugger will show you all the variables and you can step execute the code step by step until the error occurs. If you hover over a varibale you can see the value of this variable and now you can step by step try to understand the cause of the exception and solve it. If you step to deeply into the code you will end in the java class that is responsible for doing the division, if you haven't added the jars with the source code of this classes to your project the debugger isn't able to show you something at this point.

这篇关于看似无用的调试环境为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆