尝试填充ListView的Firebase API初始化失败

时间:2018-08-13 21:21:05

标签: android firebase android-studio firebase-realtime-database

我正在尝试制作一个消息传递应用程序,并试图从数据库中获取用户列表以填充列表视图。当我尝试运行该应用程序之前,从未发生过Thes错误。每次我进入listview活动时,应用程序都会崩溃并显示以下错误。由于某些原因,我收到此错误(Logcat):

08-13 13:49:21.434 15291-15291/com.example.paen3.mychatapp E/FirebaseApp: Firebase API initialization failure.
                                                                      java.lang.reflect.InvocationTargetException
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.google.firebase.FirebaseApp.zza(SourceFile:739)
                                                                          at com.google.firebase.FirebaseApp.zze(SourceFile:709)
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:328)
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:294)
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:281)
                                                                          at com.google.firebase.provider.FirebaseInitProvider.onCreate(SourceFile:37)
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1995)
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1970)
                                                                          at com.google.firebase.provider.FirebaseInitProvider.attachInfo(SourceFile:31)
                                                                          at android.app.ActivityThread.installProvider(ActivityThread.java:6490)
                                                                          at android.app.ActivityThread.installContentProviders(ActivityThread.java:6039)
                                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5947)
                                                                          at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1755)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6753)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                       Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbo;
                                                                          at com.google.android.gms.internal.zzcgl.zzbj(Unknown Source:0)
                                                                          at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source:0)
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.google.firebase.FirebaseApp.zza(SourceFile:739) 
                                                                          at com.google.firebase.FirebaseApp.zze(SourceFile:709) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:328) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:294) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:281) 
                                                                          at com.google.firebase.provider.FirebaseInitProvider.onCreate(SourceFile:37) 
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1995) 
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1970) 
                                                                          at com.google.firebase.provider.FirebaseInitProvider.attachInfo(SourceFile:31) 
                                                                          at android.app.ActivityThread.installProvider(ActivityThread.java:6490) 
                                                                          at android.app.ActivityThread.installContentProviders(ActivityThread.java:6039) 
                                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5947) 
                                                                          at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1755) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                          at android.os.Looper.loop(Looper.java:164) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6753) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
                                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbo" on path: DexPathList[[zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/base.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.paen3.mychatapp-2dBxa_BMt31JN6iYLJp8yQ==/lib/arm64, /system/lib64, /vendor/lib64]]
                                                                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                          at com.google.android.gms.internal.zzcgl.zzbj(Unknown Source:0) 
                                                                          at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source:0) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.google.firebase.FirebaseApp.zza(SourceFile:739) 
                                                                          at com.google.firebase.FirebaseApp.zze(SourceFile:709) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:328) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:294) 
                                                                          at com.google.firebase.FirebaseApp.initializeApp(SourceFile:281) 
                                                                          at com.google.firebase.provider.FirebaseInitProvider.onCreate(SourceFile:37) 
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1995) 
                                                                          at android.content.ContentProvider.attachInfo(ContentProvider.java:1970) 
                                                                          at com.google.firebase.provider.FirebaseInitProvider.attachInfo(SourceFile:31) 
                                                                          at android.app.ActivityThread.installProvider(ActivityThread.java:6490) 
                                                                          at android.app.ActivityThread.installContentProviders(ActivityThread.java:6039) 
                                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5947) 
                                                                          at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1755) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                          at android.os.Looper.loop(Looper.java:164) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6753) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

这是我的ListView活动代码:

    package com.example.paen3.mychatapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.firebase.ui.auth.data.model.User;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by paen3 on 8/12/2018.
 */


public class AllUsersActivity extends AppCompatActivity {


    FirebaseAuth mAuth;
    FirebaseDatabase database;
    DatabaseReference ref;
    ListView listView;
    ArrayList<String> list;
    ArrayAdapter<String> adapter;
    AllUsers user;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_users);
        user = new AllUsers();
        listView = (ListView) findViewById(R.id.listViewUsers);
        database = FirebaseDatabase.getInstance();
        ref = database.getReference("user");
        list = new ArrayList<>();
        adapter = new ArrayAdapter<String>(this,R.layout.all_user_display_layout,R.id.all_users_email, list);
        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                for(DataSnapshot ds: dataSnapshot.getChildren()){
                    user = ds.getValue(AllUsers.class);
                    list.add(user.getUser_email());
                }
                listView.setAdapter(adapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        if(item.getItemId() == R.id.main_logout_button){
            mAuth.signOut();
            LogOutUser();

        }
        return true;
    }


    private void LogOutUser() {
        Intent LoginIntent = new Intent(AllUsersActivity.this, MainActivity.class);
        LoginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(LoginIntent);
        finish();
    }

}

0 个答案:

没有答案