1

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>

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

this worked for me. i was using app:context=".MainActivity" instead of tools:context=".MainActivity" and changing that did the trick. I am also new to android programming with kotlin and i'm following the official docs. Its interesting
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.