![](/img/trans.png)
[英]Android Firebase java.lang.StackOverflowError: stack size 8MB error when user is uploading an image
[英]Android Firebase Realtime Exception java.lang.StackOverflowError: stack size 8MB
我有一個問題異常java.lang.StackOverflowError:我的應用程序中堆棧大小為8MB,所以我試圖將對象的屬性(Uri,brand,matricule ...)添加到其對象中的特定用戶。我的密碼
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即可將其添加到數據庫中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.