xml – error: No resource identifier found for attribute 'textAlignment' in package 'android'-ThrowExceptions

Exception or error:

This is my res/layout mobile.xml file. Where is my mistake? When I run textview has this error.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp" >
    <ImageView
    android:id="@+id/grid_item_image"
    android:layout_width="100dp"
    android:layout_height="118dp"
    android:src="@drawable/android_logo" >
    </ImageView>
    <TextView
    android:id="@+id/grid_item_label"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:text="@+id/label"
    android:textSize="25dp"
    android:textAlignment="center" >
    </TextView>
    </LinearLayout>
How to solve:

textAlignment was added in API level 17 (Android 4.2).

Your emulator/device will need to be running 4.2+ for this to work.

Otherwise just use android:gravity="center"

<TextView
    android:id="@+id/grid_item_label"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:text="@+id/label"
    android:textSize="25dp"
    android:gravity="center" />

###

I think what problem could be in this line:

android:text="@+id/label"

try this:

android:text="@string/label"

Leave a Reply

Your email address will not be published. Required fields are marked *