Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My Android XML Layout is Showing Following Error, It not Showing The **Preview** Of The Layout:


**NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.**

**Exception raised during rendering: android.widget.TextView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log**

My **activity.xml** file is as follows:


<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

   <TextView
       android:id="@+id/textView1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="10dp"
       android:removed="#069c88"
       android:gravity="center"
       android:text="Home"
       android:textColor="#fffff"
       android:textSize="30dp" >

       <TextView
           android:id="@+id/textView2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:gravity="center"
           android:paddingTop="20dp"
           android:text="Welcome admin"
           android:textAppearance="?android:attr/textAppearanceLarge" />
   </TextView>


   </LinearLayout>
Posted
Updated 10-Mar-21 21:36pm
Comments
Richard MacCutchan 30-Aug-14 5:26am    
The build system says you have compilation errors, so you need to fix them first. And I don't think you can have a TextView inside another one.

Use this .,. It will Work.
Java
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="Home"
        android:textColor="#121212"
        android:textSize="30dp" >
    </TextView>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="20dp"
        android:text="Welcome admin"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>
 
Share this answer
 
Your TextView named textView1 has not been terminated properly.
 
Share this answer
 
Comments
Richard Deeming 5-Sep-17 13:13pm    
Only three years too late!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900