使用FirebaseListAdapter时的构造函数错误

时间:2016-12-06 21:34:52

标签: android firebase firebaseui

我正在尝试使用FirebaseListAdapter创建包含产品名称的ListView,但我收到此错误:

error: no suitable constructor found for
FirebaseListAdapter(MainActivity,Class<String>,int,Firebase) constructor
FirebaseListAdapter.FirebaseListAdapter(Activity,Class<String>,int,Query)
is not applicable

我有最新版本的Google Play服务和Google Repository,如此屏幕截图所示:

enter image description here

我的build.gradle(root)是:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    classpath 'com.google.gms:google-services:3.0.0'
}

我的build.gradle(app)是:

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.firebase:firebase-client-android:2.4.0'
    compile 'com.firebaseui:firebase-ui:0.4.1'

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

我使用的代码是:

public class MainActivity extends AppCompatActivity {
    Firebase firebase;
    ArrayList<String> arrayList = new ArrayList<>();
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Firebase.setAndroidContext(this);
    firebase = new Firebase(Config.FIREBASE_URL);
    listView = (ListView) findViewById(R.id.listView);
    }

    @Override
    protected void onStart() {
    super.onStart();

    Firebase products = firebase.child("names");
    FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(this, String.class, String.class, android.R.layout.simple_list_item_1, products) {
        @Override
        protected void populateView(View v, String model, int position) {
        //
        }
    };
    }
}

我尝试了所有类似问题的解决方案,但没有运气。提前谢谢!

2 个答案:

答案 0 :(得分:1)

您正在混合新SDK:

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'

使用旧版SDK:

compile 'com.firebase:firebase-client-android:2.4.0'
compile 'com.firebaseui:firebase-ui:0.4.1'

它们不兼容。进行此更改:

//compile 'com.firebase:firebase-client-android:2.4.0'
compile 'com.firebaseui:firebase-ui:1.0.1'

并查看Firebase Upgrade Guide以了解所需的代码更改。

如果您不需要新SDK的功能,那么我认为您可以删除这些依赖项并使用旧版SDK运行。我没有尝试过,也不知道你是否会遇到其他问题。

答案 1 :(得分:0)

尝试这种方式:

FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(this, String.class,  android.R.layout.simple_list_item_1, products) {
    @Override
    protected void populateView(View v, String model) {
    //
    }
};

FirebaseListAdapter populateView方法只有两个参数和String.class,是两次。