Android Firebase Realtime Exception java.lang.StackOverflowError:堆栈大小为8MB

时间:2018-03-12 00:16:06

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

我有一个问题异常java.lang.StackOverflowError:我的应用程序中的堆栈大小为8MB,所以我试图添加一个对象CAR有其attribuetes(Uri,品牌,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();

        }
    });
}

你能帮帮我解决这个问题!

enter image description here

1 个答案:

答案 0 :(得分:0)

改变这个:

downloadeduri= taskSnapshot.getDownloadUrl();

到此:

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

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