如何让Eclipse告诉我哪一行出错?

时间:2013-10-09 08:07:56

标签: java android eclipse exception nullpointerexception

来自Python我现在正在尝试创建一个Android应用程序。在这种情况下,我有时会遇到错误,例如NullPointerException。问题是,与Python不同,Eclipse不会告诉我发生错误的行号。它只是给了我这样的东西:

10-09 10:03:59.379: E/AndroidRuntime(3289): java.lang.RuntimeException: Unable to resume activity {com.example.android/com.example.android.ui.MyActivity}: java.lang.NullPointerException

有没有办法让Eclipse告诉我发生NullPointerException的行?

===编辑=== 啊,我现在看起来更详细的完整错误(下面),在那里我看到这一行:om.example.android.ui.MyActivity.onResume(MyActivity.java:208),这确实是它发生的行。

那么我们就这样提出我的问题吧。我可以只显示我自己编写的代码中的错误,而不是其他所有的mumbo-jumbo中的错误吗?

10-09 10:08:49.759: E/AndroidRuntime(3502): java.lang.RuntimeException: Unable to resume activity {com.example.android/com.example.android.ui.MyActivity}: java.lang.NullPointerException
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.os.Looper.loop(Looper.java:137)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at java.lang.reflect.Method.invoke(Method.java:525)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at dalvik.system.NativeStart.main(Native Method)
10-09 10:08:49.759: E/AndroidRuntime(3502): Caused by: java.lang.NullPointerException
10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.example.android.ui.widget.AmountFragment.setAmount(AmountFragment.java:79)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.example.android.ui.MyActivity.onResume(MyActivity.java:208)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.Activity.performResume(Activity.java:5211)
10-09 10:08:49.759: E/AndroidRuntime(3502):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
10-09 10:08:49.759: E/AndroidRuntime(3502):     ... 12 more

2 个答案:

答案 0 :(得分:3)

错误位于AmountFragment.Java的第79行。该行的句子试图对一个null的实例做一些事情。

DDMS透视图为您提供了很多调试透视图的信息。在ddms透视图中,您可以使用线程和每个线程使用的内存,每个应用程序的内存,请参阅应用程序和模拟器堆,分配跟踪器(这里可以执行异步任务),logcat比调试控制台要好得多。其中一个最有用的功能是方法分析,您可以在其中逐步执行应用程序执行的操作。

也许这段视频对您调试Android应用很有帮助:How To Debug Android Applications in Eclipse

答案 1 :(得分:0)

这一行告诉你:

                                                 Caused by: java.lang.NullPointerException
 10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.example.android.ui.widget.AmountFragment.setAmount(AmountFragment.java:79)
 10-09 10:08:49.759: E/AndroidRuntime(3502):     at com.example.android.ui.MyActivity.onResume(MyActivity.java:208)