当前位置: 首页 > 知识库问答 >
问题:

Android使用Firebase构建APK工作良好但发布APK崩溃

高嘉树
2023-03-14
public class Gallery extends AppCompatActivity {
static ArrayList<String> images;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("Gallery");

        toolbar.setTitleTextColor(ContextCompat.getColor(Gallery.this, R.color.white));
        images = new ArrayList<>();
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        final GridView gridview = (GridView) findViewById(R.id.gridview);
        final ProgressDialog progressDialog = new ProgressDialog(Gallery.this);
        progressDialog.setMessage("Loading data...");
        progressDialog.show();
        ConnectivityManager manager = (ConnectivityManager) getApplicationContext().getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();
        final boolean isconnected = info != null && info.isConnectedOrConnecting();
        Firebase.setAndroidContext(Gallery.this);
        if (Firebase.getDefaultConfig().isPersistenceEnabled() == false)   //check if persistence is enabled or disbled
            Firebase.getDefaultConfig().setPersistenceEnabled(true);
        String URL = "someurl";
        Firebase firebase = new Firebase(URL);
        final ImageAdapter adapter = new ImageAdapter(Gallery.this, images);

        final Firebase imagefolder = firebase.child("imagesfolder");
        imagefolder.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    images.add(snapshot.getValue(String.class));
                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

}}

这是android设备监视器的崩溃报告

共有1个答案

金钊
2023-03-14

该错误通过使用DatabaseReference类而不是使用Firebase来解决

private DatabaseReference mDatabase;
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    mDatabase=database.getReference().child("imagesfolder");
    final ImageAdapter adapter = new ImageAdapter(Gallery.this, images);
     mDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    images.add(snapshot.getValue(String.class));
                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
 类似资料: