findViewById 抛出 RuntimeException
我修改了 main.xml,然后我的 Android 应用程序崩溃了。
我运行调试器并发现它引发了 RuntimeException
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
我无法理解程序中的错误所在。我将代码一分为二,发现这一行抛出了它:
giveUpButton = (Button) findViewById(R.id.GiveUpButton);
我确定,因为在我删除这一行后异常消失了。
我不知道。为什么堆栈顶部不是 findViewById
?为什么会抛出异常?
我在 main.xml 中有这段代码:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/give_up_button"
android:id="@+id/GiveUpButton"/>
I modified my main.xml and my android app crashed.
I run debugger and find it threw a RuntimeException in
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
I can't understand where the bug is in my program. I bisected the code, and find this line threw it:
giveUpButton = (Button) findViewById(R.id.GiveUpButton);
I'm sure because the exception disappeared after I removed this line.
I have no any idea. Why isn't the top of stack findViewById
? Why does it throw exception?
I have this code in main.xml:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/give_up_button"
android:id="@+id/GiveUpButton"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这听起来像个笑话。但我已经通过重新启动 Eclipse 解决了这个问题。
这很可能是由 Git 的 checkout 引起的。我在分支之间切换而不关闭 Eclipse。
我怎样才能避免这样的问题呢?一遍又一遍地重新启动Eclipse花费了大量的时间。
I know it sounds like a joke. But I have fixed the problem by... restarting my Eclipse.
It's very likely caused by Git's checkout. I switch between branches without closing Eclipse.
How can I avoid such a problem? It cost a lot of time to restart Eclipse over and over again.
吗
你在排队之前
did you
before the line