我不明白为什么我会收到类转换异常,因为我只是将 Imageview 分配给 Imageview,但它指出不能将 ImageView 转换为 TextView。
下面是我的 xml 和 Activity 类的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/review_tbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="10dp" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp" >
<TextView
android:id="@+id/toi_lbl"
android:background="@color/titlebackgroundcolor"
android:text="Times Of India :"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/toi_txt"
android:background="@color/titlebackgroundcolor"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<ImageView
android:id="@+id/txt1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/star"
android:textDirection="firstStrong" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp" >
<TextView
android:id="@+id/imdb_lbl"
android:background="@color/titlebackgroundcolor"
android:text="Imdb.com :"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/imdb_txt"
android:background="@color/titlebackgroundcolor"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/txt1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/star"
android:gravity="center"
android:text=""
android:textAlignment="center"
android:textColor="@color/titlebackgroundcolor"
android:textDirection="firstStrong" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp" >
<TextView
android:id="@+id/in_lbl"
android:background="@color/titlebackgroundcolor"
android:text="In.com :"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/in_txt"
android:background="@color/titlebackgroundcolor"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/txt1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/star"
android:gravity="center"
android:text=""
android:textAlignment="center"
android:textColor="@color/titlebackgroundcolor"
android:textDirection="firstStrong" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:src="@drawable/loading" />
<TextView
android:id="@+id/movieName_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Ranjhana"
android:textColor="@color/titletextcolor"
android:textSize="15dip"
android:textStyle="bold"
/>
<TextView
android:id="@+id/reldate_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/movieName_txt"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Released On : 12 June 2013"
android:textColor="@color/titletextcolor" />
<TextView
android:id="@+id/starring_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/reldate_txt"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Cast : Sonam Kapoor,Dhanush"
android:textColor="@color/titletextcolor" />
<TextView
android:id="@+id/director_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/starring_txt"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Director : Koi Hai"
android:textColor="@color/titletextcolor" />
<TextView
android:id="@+id/producer_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/director_txt"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Producer : Koi Hai"
android:textColor="@color/titletextcolor" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a151e2b670cd233"
android:layout_below="@+id/producer_txt"
ads:loadAdOnCreate="true" />
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/adView" >
<TextView
android:id="@+id/description_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textAlignment="gravity"
android:layout_below="@+id/producer_txt"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:textSize="15dip"
android:text=" Raanjhanaa is an upcoming 2013 Hindi romance film, directed by Anand L. Rai and written by Himanshu Sharma. The film is produced by Krishika Lulla under the banner Eros International. The film stars Tamil film actor Dhanush in his Bollywood debut and Sonam Kapoor in the lead roles.[2] The film is scheduled to release on June 21, 2013 along with a dubbed Tamil version called Ambikapathy"
android:textColor="@color/titletextcolor" />
</ScrollView>
<ImageButton
android:id="@+id/share_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignTop="@+id/movieName_txt"
android:layout_toRightOf="@+id/movieName_txt"
android:onClick="shareIt"
android:src="@drawable/shareicon" />
</RelativeLayout>
我的活动:
super.onCreate(savedInstanceState);
setContentView(R.layout.film_detail);
ImageView movieImage = (ImageView)findViewById(R.id.imageView1);
我在这条线上遇到了例外。
ImageView movieImage = (ImageView)findViewById(R.id.imageView1);
谢谢,阿曼迪普