Search code examples
androidfirebasefirebaseui

Constructor error when using FirebaseListAdapter


I am trying to use FirebaseListAdapter to create a ListView that contains product names, but I'm getting this error:

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

I have the latest version of Google Play Services and Google Repository as shown in this screenshot:

enter image description here

My build.gradle (root) is:

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

and my build.gradle (app) is:

    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'

The code that I'm using is this:

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) {
        //
        }
    };
    }
}

I tried all the solutions that I found for similar issues, but no luck. Thanks in advance!


Solution

  • You are mixing the new 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'
    

    With the legacy SDK:

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

    They are not compatible. Make this change:

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

    And review the Firebase Upgrade Guide to get an understanding of the code changes needed.

    If you don't need the capabilities of the new SDK, then I suppose you could remove those dependencies and run with the legacy SDK. I haven't tried that and don't know if you will encounter other issues.