从 XML 获取 EditText 字段
我的应用程序中有一个活动,当我拨打该线路时,
EditText username = (EditText)findViewById(R.id.usernameText);
应用程序崩溃了,这是为什么?
I have an activity in my app, when i call the line
EditText username = (EditText)findViewById(R.id.usernameText);
the app crashes, why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
视图尚未膨胀,或者您失踪了
The view has not been inflated, or you are missing
是的,要么 setContentView 尚未在活动的 onCreate 中调用,要么您尝试获取的视图不是 EditText。您遇到的异常是什么?如果它是 ClassCast 那么它不是一个 EditText。
Yeah either setContentView hasn't been called in onCreate of the activity, or else the view you are trying to get isn't an EditText. What is the Exception you are getting? If its ClassCast then its not an EditText.
由于没有提供更多信息,需要检查的事项:
另外,如果您可以编辑帖子并添加混乱的日志,它会更容易回复。
Things to check as no more information is provided:
Also, if you can edit the post and add the log of what's messing up, it will be more easy to reply.