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

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

问题描述

我刚刚开始调试我的第一个三线长的Android应用程序,我似乎不能像我想要的那样使用调试工具。
这是我的代码:

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

现在我期望调试器停止线程,并显示我的行号发生零除数的语句。不,而是在系统内部显示一些其他方法 。为了使事情变得更糟,也没有例外信息。



在此应用程序之前,我创建了一个按下按钮时会执行某些操作的应用程序。如果有任何异常提出,再次没有有用的行号或异常消息将被显示。



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



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

解决方案

起初我不得不承认你是对的。有一些调试器会在异常时停止执行,并显示导致它的代码行。我很想在eclipse调试器中看到这种行为。但其他的答案是正确的。



当您在Eclipse中时,转到窗口 - >显示视图 - >其他 - > Android - > LogCat
现在您将获得发生的所有调试输出在仿真器或连接的设备上。
有了你的例子我将得到以下StackTrace。

  T03-18 09:45:12.398:错误/ AndroidRuntime(1778):未捕获的处理程序:线程主要由于未捕获的异常退出
03-18 09:45:12.428:错误/ AndroidRuntime(1778):java.lang.RuntimeException:无法启动活动ComponentInfo {android.client / android.client.ClientMain}:java.lang.ArithmeticException:divide由零
03-18 09:45:12.428:错误/ AndroidRuntime(1778):在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:错误/ AndroidRuntime(1778):在android.app.ActivityThread.access $ 2100(ActivityThread.java:116)
03-18 09:45:12.428:错误/ AndroidRuntime(1778):android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1794)
03 -18 09:45:12.428:错误/ AndroidRuntime(1778):android.os.Handler.dispatchMessage(Handler.java:99)
03-18 09:4 5:12.428:ERROR / AndroidRuntime(1778):在android.os.Looper.loop(Looper.java:123)
03-18 09:45:12.428:错误/ AndroidRuntime(1778):在android.app .ActivityThread.main(ActivityThread.java:4203)
03-18 09:45:12.428:错误/ AndroidRuntime(1778):java.lang.reflect.Method.invokeNative(Native Method)
03 -18 09:45:12.428:ERROR / AndroidRuntime(1778):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:错误/ AndroidRuntime(1778):在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:错误/ AndroidRuntime(1778):引起的:java.lang.ArithmeticException:除以零
03-18 09:45:12.428:错误/ AndroidRuntime(1778):在android.client .ClientMain.onCreate(Cli entMain.java:35)
03-18 09:45:12.428:错误/ AndroidRuntime(1778):在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更多
03-18 09:45:12.438:INFO / Process(52):发送信号。 PID:1778 SIG:3

如果你去最深的异常显示,提出所有其他人您将看到

  03-18 09:45:12.428:错误/ AndroidRuntime(1778):引起:java.lang。 ArithmeticException:除以零
03-18 09:45:12.428:错误/ AndroidRuntime(1778):在android.client.ClientMain.onCreate(ClientMain.java:35)

这很清楚我想。在ClientMain的第35行,抛出异常,它除以零异常。如果您无法确定这一点(在这种情况下不如示例那么清楚),您可以在此行或方法的入口点设置断点。现在调试器会显示所有变量,您可以逐步执行代码,直到发生错误。如果你将鼠标悬停在一个varibale上,你可以看到这个变量的值,现在你可以一步一步地尝试了解异常的原因并解决它。如果您深入了解代码,那么您将在负责进行划分的Java类中结束,如果尚未将具有此类源代码的jar添加到项目中,则调试器无法显示在这一点上的东西


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.

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?

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

解决方案

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.

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)

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天全站免登陆