【问题标题】:Android Firebase Realtime Exception java.lang.StackOverflowError: stack size 8MBAndroid Firebase 实时异常 java.lang.StackOverflowError:堆栈大小 8MB
【发布时间】:2018-03-25 00:09:50
【问题描述】:

我有一个问题 Exception java.lang.StackOverflowError: stack size 8MB in my aplication ,所以我试图添加一个对象 CAR 有它的属性(Uri、brand、matricule...)到一个特定的用户在它的 chlid汽车 这是我的代码

public void uploadtothefirebase() {

    progressBar = findViewById(R.id.progressBar3);
    auth = FirebaseAuth.getInstance();
    database = FirebaseDatabase.getInstance();
    reference = database.getReference("User");

    // Upload the pic to the Firebase storage and save the Uri and set it in the Realtime
    storage= FirebaseStorage.getInstance().getReference();
    StorageReference filepath = storage.child("photoscars").child(uricarimage.getLastPathSegment());
    filepath.putFile(uricarimage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            auth = FirebaseAuth.getInstance();
            downloadeduri= taskSnapshot.getDownloadUrl();
            Toast.makeText(getApplicationContext(),"Uri = "+downloadeduri.toString(),Toast.LENGTH_SHORT).show();

            progressBar = findViewById(R.id.progressBar3);
            auth = FirebaseAuth.getInstance();
            database = FirebaseDatabase.getInstance();
            reference = database.getReference("User");
            assert firebaseUser != null;
            firebaseUser = auth.getCurrentUser();

            reference.orderByChild("fullName").equalTo(firebaseUser.getDisplayName()).addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    String Uid= dataSnapshot.getKey();
                    brand = inputbrand.getText().toString();
                    matricule = inputmatricule.getText().toString();
                    numcartegrise = inputcartegrise.getText().toString();
                    progressBar = findViewById(R.id.progressBar3);


                    car = new Car(downloadeduri,brand,spin_val,matricule,numcartegrise);
                    reference.child(Uid).setValue(car);

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






            progressBar.setVisibility(View.GONE);
            final AlertDialog.Builder adb = new AlertDialog.Builder(Setinformationcar.this);
            adb.setTitle("The Car has Added ");
            adb.setMessage("The Car has Added To Your List You can Use it to Create Trip ");
            adb.setCancelable(false);

            adb.setPositiveButton(" OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    startActivity(new Intent(getApplication(),Mycars.class));
                    finish();
                }});

            adb.show();

        }
    });
}

你能帮我解决这个问题吗?

【问题讨论】:

    标签: java android firebase firebase-realtime-database stack-overflow


    【解决方案1】:

    改变这个:

    downloadeduri= taskSnapshot.getDownloadUrl();
    

    到这里:

    String downloadeduri= taskSnapshot.getDownloadUrl().toString();
    

    Firebase 不接受数据库中的 uri,因此将其转换为 String 以便能够将其添加到数据库中。

    【讨论】:

    • @user8173031 不要忘记 ▲ 点赞有帮助的答案,并 ✓+▲ 接受并点赞帮助您解决问题的答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多