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 a Simple Android App Basic Android Programming Accessing Views in Code: Declaring Variables

Lucas Santos
Lucas Santos
19,315 Points

Did not get AppCompatActivity, instead got ActionBarActivity

I have been following along in this course fine until now because for some reason my "FunFactsActivity.java" file is different then the one shown in the video.

It looks like this:

package com.teamtreehouse.funfacts;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class FunFactsActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fun_facts);
    }
}

This gives me an error with a red line under:

public class FunFactsActivity extends ActionBarActivity

it says:

class FunFactActivity must either be declared abstract or implement abstract method 'getSupportFragmentManager()' in 'Callback'

in the video the code is the same but instead of extends ActionBarActivity it's extends AppCompatActivity and when I tried switching to that it gave me an error as well on AppCompatActivity which turned red.

Assistance is appreciated, thank you.

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Since you changed the class manually, you likely didn't add the class's import statement toward the top of the code.

Click to place the cursor on the red-underlined AppCompatActivity. Then either type Alt+Enter or click the red lightbulb to the left. In the drop-down menu that shows up, select Import Class. That should fix the error.

Lucas Santos
Lucas Santos
19,315 Points

When I click on the red lightbulb or press Alt Enter it only gives me one option and thats to create class 'AppCompatActivity'

I do not see import at all

Lucas Santos
Lucas Santos
19,315 Points

Iv been reading and it says it has something to do with my build.gradle file. If you know of anything or if this is of any use let me know.

This is my file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.lucazdesign.funfacts"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:19.1.0'
}
Ben Deitch
Ben Deitch
Treehouse Teacher

Hey Lucas!

Here's the build.gradle from the app as I have it:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.teamtreehouse.funfacts"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
}

You're using an older version (19) of the support library which doesn't yet include the AppCompatActivity class. Updating your build.gradle should fix your issues, and if you don't have the right version installed on your computer it should prompt you to download them.