Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot setup floating action buttons as class cannot be found (Android Studio)

Tags:

android

So I am pretty new to android and I am trying to setup a floating action button with the Android Design Support Library using this guide in Android Studio.

My Project: Noted build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

My Module: app build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.noted"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:design:22.2.0'
}

In myactivity_main.xml I try to implement

<android.support.design.widget.FloatingActionButton 
    ... />

but I get one of those Rendering Problems pop ups after building saying:

The following classes could not be found: -android.support.design.widget.FloatingActionButton

My guess is that I'm doing something wrong with my dependencies but I really have no idea. I have been trying to get this to work for hours with no luck and would really appreciate any help.

Thanks!

like image 628
Jtaks Avatar asked Jun 09 '15 17:06

Jtaks


2 Answers

I have been facing this problem recently and tried to change dependencies version, invalidating caches and restart, etc. The preview rendered once and then reopening my xml file, it raised the same error.

Clicking on the refresh button at the preview window solved to me (momentarily) the problem, letting me see the layout and its elements properly.

Preview window at xml file

like image 152
Julián Martínez Avatar answered Sep 21 '22 23:09

Julián Martínez


I had the same issue and updated the Android Support Repository", "Android Support Library"(22.2.1) and "Android SDK Tool"(24.1.2) using SDK manager now its working fine. Once update finish rebuild the project. For more https://developer.android.com/tools/support-library/setup.html

like image 43
Niroshan Avatar answered Sep 20 '22 23:09

Niroshan