我在用Kotlin。我试着用这里找到的毫秒天文钟,https://github.com/antoniom/Millisecond-Chronometer。我下载了the文件,然后在我的项目中将Chronometer.java文件复制到一个新的.java文件中。
我在布局文件中放置了一个计时器小部件,并给出了它的id chrono。
当我尝试使用Chronometer.java时,它会抛出一个错误:
val mChronometer = findViewById<Chronometer>(R.id.chrono)
//Caused by: java.lang.ClassCastException: android.widget.Chronometer cannot be cast to com.example.rinor.chronometertimer.Chronometer怎么解决这个问题?我相信如果我把这条线弄好了,从那以后其他的一切都会一帆风顺的。
发布于 2018-09-06 10:45:15
可能您在.xml <Chronometer>...</Chronometer>中使用了错误的计时表而不是
<com.example.rinor.chronometertimer.Chronometer
android:layout_width="match_parent"
android:layout_height="wrap_content">...
</com.example.rinor.chronometertimer.Chronometer>发布于 2018-09-06 10:42:44
您可能导入了"android.widget.Chronometer“而不是"com.example.rinor.chronometertimer.Chronometer”,更改了导入。
https://stackoverflow.com/questions/52198301
复制相似问题