Prasenjit Chatterjee
Prasenjit Chatterjee

Reputation: 11

error: attribute 'android:context' not found

error: attribute 'android:context' not found. Message{kind=ERROR, text=error: attribute 'android:context' not found., sources=[C:\Users\eMotion4\AndroidStudioProjects\BSMAS\app\src\main\res\layout\activity_splashactivity.xml:2], original message=, tool name=Optional.of(AAPT)}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF9B1F1C"
    android:context=".splashactivity">

<ImageView
        android:layout_width="120dp"
        android:src="@drawable/bharatsathi"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/bharatsathi"

    />
</RelativeLayout>

Upvotes: 1

Views: 5488

Answers (2)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29794

This is simply because you're using incorrect attribute for context. You need to use tools:context instead of android:context. So, update your xml to use it like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF9B1F1C"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".splashactivity">

<ImageView
        android:layout_width="120dp"
        android:src="@drawable/bharatsathi"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/bharatsathi"

    />
</RelativeLayout>

Upvotes: 1

Doc
Doc

Reputation: 11651

Classes are case-sensitive.

android:context=".splashactivity"

means there should be an Activity sub-class named splashactivity in your source code root folder. Make sure it is present. This will be a sub-class of AppCompatActivity which extends from Activity.

Your class will use the layout mentioned in the posted code by calling setContentView(R.layout.activity_splashactivity);.


Note: In Java/Kotlin the preferred name will be SplashActivity according to naming conventions.

Upvotes: 0

Related Questions