I declared a ImageView on my layout (XML) but when I try to grab it by the ID I’m getting a TextField!?! Then my code throw a ClassCastException.
Here is my layout code (splash.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
style="@android:style/Theme.Light" android:layout_height="wrap_content" android:background="@drawable/bg">
<ImageView android:layout_height="wrap_content" android:layout_width="match_parent" android:src="@drawable/splash" android:layout_marginTop="20pt" android:id="@+id/splashLogo"></ImageView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:id="@+id/splashTitle" android:textStyle="bold" android:textSize="@dimen/title_size" android:layout_gravity="center" android:lineSpacingExtra="@dimen/spacer" android:gravity="center"></TextView>
<TextView android:id="@+id/splashCopyleft" android:textSize="@dimen/version_size" android:lineSpacingExtra="@dimen/version_spacing" android:layout_width="wrap_content" android:gravity="center" android:layout_height="wrap_content" android:text="@string/app_version_info" android:layout_gravity="center" android:textColor="@color/version"></TextView>
</LinearLayout>
Here is my Java (Activity) code:
// imports
public class SplashActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// Grab a ClassCastException here
ImageView logo = (ImageView) findViewById(R.id.splashLogo);
// Never get here :'(
Log.i("GOT", logo.toString());
}
}
Sometimes Eclipse shifts resource ids. Try cleaning your project and building it again.