我有一个问题异常java.lang.StackOverflowError:我的应用程序中的堆栈大小为8MB,所以我试图向对象添加具有其属性(Uri,brand,matricule ...)的对象CAR到其Chlid Cars中的特定用户。
这是我的代码
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();
}
});
}
你能帮我解决这个问题!
最佳答案
更改此:
downloadeduri= taskSnapshot.getDownloadUrl();
对此:
String downloadeduri= taskSnapshot.getDownloadUrl().toString();
Firebase在数据库中不接受uri,因此将其强制转换为String即可将其添加到数据库中。