Я объявил ImageView на своем макете (XML), но когда я пытаюсь получить его по идентификатору, я получаю TextField!?!Затем мой код выдает ClassCastException
.
Вот мой код компоновки (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>
Вот мой код Java (Activity):
// 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());
}
}