6

Recently I have downloaded a code from GitHub and synced it with my android studio. I have faced lots of errors and issues while doing so and somehow fixed most of them. However, the last issue I'm stuck at right now is that my android studio cannot find the class FloatingActionButton as you can see in this screenshot screenshot

It is to be noted that earlier many other classes, including 'AppCompatActivity' could not be resolved. Changing the dependencies to following solved the issue

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

But even after changing dependencies, clean building the project, doing 'Invalidate Caches / Restart...', the problem with 'FloatingActionButton' is still there.

You can check the repository here And this is the java code of the activity where the error is occurring

Zoe
  • 27,060
  • 21
  • 118
  • 148
ganjaam
  • 1,030
  • 3
  • 17
  • 29

3 Answers3

12

The FloatingActionButton is in the design library.

Add this line to your dependencies:

implementation 'com.android.support:design:27.1.1'

This post also has more general info about FloatingActionButton: FloatingActionButton example with Support Library

Sub 6 Resources
  • 1,674
  • 15
  • 31
1

@Sub 6 Resources already answered this question wholly but I want to add a bonus tip. If you already added implementation 'com.android.support:design:27.1.1' to your code and the compiler can't still resolve the FloatingActionButton class, simply rebuild your project. A colleague and I recently had this same problem while the dependency was already there and a simple rebuild solved it all.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
0

Update for AndroidX:

The answer of @Sub 6 Resources was perfect before androidX was introduced. Now, it is better to include the following dependency instead of the accepted answer's dependency:

implementation 'com.google.android.material:material:1.6.1'

NOTE: it might not be the latest version by the time you are reading this.

ganjaam
  • 1,030
  • 3
  • 17
  • 29