三星总是返回 null,但它适用于 HTC - findViewbyId
我有一个奇怪的问题,非常奇怪。在 xml 中,我有
<Button
android:id="@+id/btnV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="10dp"
android:background="@drawable/selector_app_update">
</Button>
,在代码中
btnV = (Button) findViewById(R.id.btnV);
,在 HTC 上它可以工作,但在三星上我每次都得到 null。有人有类似的问题吗?我清理并重新启动了项目和 Eclipse,但什么也没有。
I have strange problem, very strange. In xml I have
<Button
android:id="@+id/btnV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="10dp"
android:background="@drawable/selector_app_update">
</Button>
and in code
btnV = (Button) findViewById(R.id.btnV);
and on HTC it works but on Samsung I am getting null every time. Did anyone have similar problem ? I cleaned and restarted project and eclipse but nothing .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能是您的自定义背景可绘制。
这些设备的屏幕尺寸或 DPI 是否不同?
您在drawable-ldpi和drawable-hdpi中是否有不同的drawable,但在标准drawable文件夹中没有?
Problem could be your custom background drawable.
Do these devices have different screen sizes or DPI?
Do you have different drawables in drawable-ldpi and drawable-hdpi but not in the standard drawable folder?
这听起来确实很奇怪,通常我会要求您清理项目,甚至可能重新启动 Eclipse,但从表面上看,您已经尝试过了。
重命名
Button
视图的 ID 怎么样?你尝试过吗?您能否显示初始化布局和
Button
的代码部分?This does sound very strange and normally I would have asked you to clean the project and possibly even restart Eclipse, but by the looks of it, you've already tried that.
How about renaming the ID of your
Button
view? Have you tried that?Can you please show the part of your code where you initialize the layout and
Button
?