Opp*_*cke 9 android classcastexception
使用eclipse和Android SDK,我使用Button和ProgressBar管理了一个简单的测试应用程序.所有运行良好,但我我以前不想要的进度移动的按钮,当进度已变得可见,所以只是为了测试我改变了他们在res /布局/ main.xml中文件中定义(它使用的顺序LinearLayout中).编译并运行我然后在下面的"final ProgressBar ..."行中获得ClassCastException.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* 01-06 14:37:39.590: E/AndroidRuntime(863): java.lang.RuntimeException:
java.lang.ClassCastException: android.widget.Button cannot be cast to
android.widget.ProgressBar */
final ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressBar1); /* here */
progressbar.setVisibility(ProgressBar.GONE);
final Button exebutton = (Button)findViewById(R.id.button1);
exebutton.setOnClickListener(new View.OnClickListener()
// etc...
Run Code Online (Sandbox Code Playgroud)
现在,我理解ClasCastException的含义和含义,我只是不明白为什么会出现.我不是试图将Button转换为ProgressBar.我不明白......
它看起来像这一行:
final ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressBar1); /* here */
Run Code Online (Sandbox Code Playgroud)
正在将一个Button转换为进度条.
这意味着findViewById返回按钮R.id.progressBar1.
既然你说你改变了顺序,看起来这个id仍然对应于按钮.这表明生成的文件存在问题.我会做一个Project/Clean.
| 归档时间: |
|
| 查看次数: |
1983 次 |
| 最近记录: |