Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从firebase数据库获取数据时显示进度对话框_Android_Firebase_Firebase Realtime Database_Progressdialog - Fatal编程技术网

Android 从firebase数据库获取数据时显示进度对话框

Android 从firebase数据库获取数据时显示进度对话框,android,firebase,firebase-realtime-database,progressdialog,Android,Firebase,Firebase Realtime Database,Progressdialog,我希望活动在从Firebase数据库获取数据时必须显示进度对话框。它没有显示任何内容,因此崩溃。下面是我的代码 公共类profilemain扩展了AppCompative活动{ private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; private ProgressDialog progressDialog; DatabaseReference mref = FirebaseDat

我希望活动在从Firebase数据库获取数据时必须显示进度对话框。它没有显示任何内容,因此崩溃。下面是我的代码

公共类profilemain扩展了AppCompative活动{

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

 private ProgressDialog progressDialog;

DatabaseReference mref = 
FirebaseDatabase.getInstance().getReference("users");
ListView mlistview;
ArrayList<String> arrayList=new ArrayList<>();
ArrayAdapter<String> arrayAdapter;

private BottomNavigationView.OnNavigationItemSelectedListener 
 mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.navigation_home:
progressDialog.show();
                startActivity(new 
Intent(profilemain.this,profilemain.class));
                return true;
            case R.id.navigation_dashboard:
                Toast.makeText(profilemain.this,"hi 
hello",Toast.LENGTH_SHORT).show();
                return true;
            case R.id.navigation_notifications:
                Toast.makeText(profilemain.this,"hi 
hello",Toast.LENGTH_SHORT).show();
                return true;
            case R.id.navigation_signout:

                Toast.makeText(profilemain.this,"You have successfully 
Signed out",Toast.LENGTH_SHORT).show();
                mAuth.signOut();
                return true;
        }
        return false;
    }

};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profilemain);
   progressDialog.setMessage("loading");
    progressDialog.setTitle("database is");

    mlistview=(ListView) findViewById(R.id.listview);

    Firebase.setAndroidContext(this);

    DatabaseReference ref = FirebaseDatabase.getInstance()
            .getReference("users");
    //mref=new Firebase("https://stark-1dffd.firebaseio.com/users");
    arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrayList);
    mlistview.setAdapter(arrayAdapter);


    mref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            String value= dataSnapshot.getValue(String.class);

            arrayList.add(value);
            arrayAdapter.notifyDataSetChanged();
            //

            //

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    mAuth = FirebaseAuth.getInstance();


    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (firebaseAuth.getCurrentUser()==null){
                startActivity(new
                        Intent(profilemain.this,MainActivity.class));

            }
        }
    };



}

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

    mAuth.addAuthStateListener(mAuthListener);
}

      Process: com.food.sheenishere.stark, PID: 16408

com.google.firebase.database.DatabaseException: Failed to convert value of type 
java.util.HashMap to String

at com.google.android.gms.internal.zg.zzb(Unknown Source)

at com.google.android.gms.internal.zg.zza(Unknown Source)

at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)

at com.food.sheenishere.stark.home$1.onChildAdded(home.java:49)

at com.google.android.gms.internal.px.zza(Unknown Source)

at com.google.android.gms.internal.vj.zzHX(Unknown Source)

   at com.google.android.gms.internal.vp.run(Unknown Source)

at android.os.Handler.handleCallback(Handler.java:751)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6119)

at java.lang.reflect.Method.invoke(Native Method)

   at 

代码中的问题是,您试图在从未初始化的
ProgressDialog
对象上使用show()、setMessage(“加载”)和setTitle(“数据库是”)方法

为了解决您的问题,您需要使用以下代码:

ProgressDialog progressDialog = new ProgressDialog(this);

它肯定会解决你的问题。

你应该初始化进度对话框。.像下面这样

 private ProgressDialog pDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    pDialog = new ProgressDialog(profilemain.this);
    pDialog.setMessage("loading..");
}

发布日志您尚未在onCreate中初始化progressDialog。
progressDialog=new progressDialog(此);
已使用logcat编辑了我的问题
 private ProgressDialog pDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    pDialog = new ProgressDialog(profilemain.this);
    pDialog.setMessage("loading..");
}