简体   繁体   中英

Android Firebase Realtime Exception java.lang.StackOverflowError: stack size 8MB

Ihave a probleme Exception java.lang.StackOverflowError: stack size 8MB in my aplication , so i'm trying to add an object CAR have its attribuetes (Uri,brand,matricule... ) To a specific User in its chlid Cars This is My code

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();

        }
    });
}

Can you Help me to solve this !!

在此处输入图片说明

Change this:

downloadeduri= taskSnapshot.getDownloadUrl();

to this:

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

Firebase does not accept uri in the database so cast it to String to be able to add it to the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM