ClassCastException:android.widget.Button [英] ClassCastException: android.widget.Button

查看:82
本文介绍了ClassCastException:android.widget.Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个非常非常奇怪的问题.

I have a really really really strange issue here.

我有这行代码:

SeekBar mProgressBar =  (SeekBar) findViewById(R.id.SeekBar);

并引发 ClassCastException:android.widget.Button ,如标题所示. XML文件如下所示:

And it throws a ClassCastException: android.widget.Button as the title indicates. The XML file looks like this:

...
<SeekBar
android:id="@+id/SeekBar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
...

如果我将代码更改为

Button mProgressBar =  (Button) findViewById(R.id.SeekBar);

有效"(例如,单行有效.由于其他原因,程序现在失败,因为它现在是一个按钮).我在另一个文件中有 exact 相同的行,没有问题.知道有什么问题吗?

It "works" (e.i that single line works. The programs then fails for other reasons because it's now a button). I have the exact same line in another file without problems. Any idea what could be wrong?

推荐答案

必须是已过时的自动生成的R类.有时候,它变得一团糟,我刚才才知道.尝试清理项目并再次重建.或更改布局XML中的内容并保存,Eclipse应该刷新R类(也就是说,如果您使用的是eclipse).

Must be an outdated auto-generated R class. Sometimes it gets messed up, i had it just moments ago. Try to clean the project and rebuild again. Or change something in the layout XML and save, Eclipse should refresh the R class (that is, if you're using eclipse).

这篇关于ClassCastException:android.widget.Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆