Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) User Input Introducing ImageViews

Error with srcCompat

I am getting the following error when trying to run the Interactive Story app:

Error:(11) No resource identifier found for attribute 'srcCompat' in package 'com.hylapad.interactivestory'

Here is my code for my XML file

<?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" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.hylapad.interactivestory.MainActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/main_title"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/titleImageView"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:contentDescription="Signals from Mars"/>

</RelativeLayout>

Here is the code for my Gradle file:

apply plugin: 'com.android.application'

android { compileSdkVersion 22 buildToolsVersion "24.0.3" defaultConfig { applicationId "com.hylapad.interactivestory" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:22.2.1' testCompile 'junit:junit:4.12' }

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

app:srcCompat was added in the support libraries in 23.2, but you're using the 22.2 version. You can either update that in build,.gradle or use the older android:src property since this project doesn't use vector drawables.

http://android-developers.blogspot.com/2016/02/android-support-library-232.html

Thank you! The app runs now without error.