尝试获取集合时,Android studio不会使.collection方法变灰

时间:2019-05-18 14:13:05

标签: android firebase google-cloud-firestore

当尝试从Firebase数据库获取集合时,发生错误。

CollectionReference usersCollectionRef = database.collection("users");

错误:找不到显示出来的符号方法集合(字符串)错误

由于某种原因,它找不到.collection方法

Build.Gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.roguerun2"
        minSdkVersion 27
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-storage:16.0.4'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    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'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'pub.devrel:easypermissions:2.0.1'
    implementation 'com.google.maps:google-maps-services:0.2.4'
    implementation 'com.google.firebase:firebase-firestore:17.0.4'
    implementation 'com.google.firebase:firebase-core:16.0.9'



}
apply plugin: 'com.google.gms.google-services'


任何帮助都会得到

1 个答案:

答案 0 :(得分:2)

您正在混合使用Firestore和实时Firebase,如果您使用Firestore,则需要执行以下操作:

FirebaseFirestore database = FirebaseFirestore.getInstance();
CollectionReference usersCollectionRef = database.collection("users");

更多信息在这里:

https://firebase.google.com/docs/firestore/quickstart