Android:无法从视图投射到计时器
我尝试遵循这个示例 ChronometerDemo.java,但遇到了一些问题:
- 我无法导入 android.widget.Chronometer; 错误:与同一文件中定义的类型冲突(导入 android.widget.Chronometer.OnChronometerTickListener)
- 我无法将 View 转换为 Chronometer mChronometer = (Chronometer) findViewById(R.id.chronometer);
有人可以帮忙吗?欣赏, 雏菊
I try to follow this example ChronometerDemo.java, but I got some problem:
- I can't import android.widget.Chronometer;
Error: conflicts with a type defined in a same file(import android.widget.Chronometer.OnChronometerTickListener) - I can't cast View to Chronometer
mChronometer = (Chronometer) findViewById(R.id.chronometer);
Anyone can help? Appreciate,
Daisy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎存在另一个不从
View
扩展的Chronometer
类,这就是您无法转换它的原因。如果没有代码,很难判断,但是您是否将ChronometerDemo.java
重命名为Chronometer.java
?ChronometerDemo
是一个 Activity,不应由findViewById
调用返回。当然,假设您正在谈论 这个。
There seems to be another
Chronometer
class present that does not extend fromView
, which is why you can't cast it. It's hard to tell without your code, but did you renameChronometerDemo.java
toChronometer.java
?ChronometerDemo
is an Activity, and is not supposed to be returned by afindViewById
call.This is, of course, assuming you're talking about this.