Using eclipse and the Android SDK, I managed a simple test app with a Button and a ProgressBar. All runs fine, except I did't want the ProgressBar to move the Button, when the ProgressBar was made visible, so just for testing I changed the order that they are defined in the res/layout/main.xml file (which uses a LinearLayout). Compiling and running I then get a ClassCastException at the "final ProgressBar ..." line below.
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...
Now, I understand what the ClasCastException says and means, I just don't understand why it appears. I am not trying to cast a Button to a ProgressBar. I don't get it...