【问题标题】:Why is my app crashing when trying to connect to firebase?为什么我的应用在尝试连接到 Firebase 时会崩溃?
【发布时间】:2019-04-04 01:26:02
【问题描述】:

在我的应用中,二维码扫描器会扫描二维码并获取其中的文本值。 然后运行此代码。 但应用程序不断崩溃。

我注释掉了部分代码,发现添加DatabaseReference部分后,应用崩溃了

    @Override
    public void handleResult(Result result) {

        final String scanResult = result.getText();


        ImageView imageView = (ImageView) findViewById(R.id.mainImageView);
        final TextView textView = (TextView) findViewById(R.id.text_view_character_name);

        DatabaseReference dbref = FirebaseDatabase.getInstance().getReference().child("stories").child(scanResult);
        dbref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                String characterName = dataSnapshot.child("name").getValue().toString();
                String downloadURL = dataSnapshot.child("DownloadURL").getValue().toString();
                textView.setText(characterName);
                setContentView(R.layout.activity_main);

            }

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

            }
        });

    }

【问题讨论】:

  • 添加堆栈跟踪
  • 如果应用程序崩溃,会有一个堆栈跟踪。请在 logcat 上查找,并将其添加到您的问题中。
  • 应用程序在手机上运行时崩溃。不在构建中。该应用程序可以完美地构建和安装在手机中。当应用程序打开手机并扫描二维码时,它开始崩溃。

标签: android firebase-realtime-database


【解决方案1】:

没有堆栈跟踪,就不可能找到原因。

但是,一个可能的原因可能是 scanResult 为空。

【讨论】:

  • 应用在手机上运行时崩溃。不在构建中。该应用程序可以完美地构建和安装在手机中。当应用程序打开手机并扫描二维码时,它开始崩溃。是否可以获得该应用程序的堆栈跟踪?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2017-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多