作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关于如何将图像保存在 Firebase 存储中,我遇到一些编码错误。并出现 2 个错误...有人可以帮助我...我的 logcat 如下...
1) 错误:找不到符号方法 setValue(String)
2) 错误:找不到符号方法addValueEventListener()
storageImage.child("Tuition Image").setValue(downloadUrl)
.addOnCompleteListener(new OnCompleteListener<Void>()
{
@Override
public void onComplete(@NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Intent ViewIntent = new Intent(AddAdsActivity.this, AddAdsActivity.class);
ViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(ViewIntent);
finish();
Toast.makeText(AddAdsActivity.this, "Tuition image has been successfully stored in Firebase Database", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
String message = task.getException().getMessage();
Toast.makeText(AddAdsActivity.this, "Error occured: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
我的第二个错误...
storageImage.child(currentUserID).addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
if(dataSnapshot.exists())
{
image = dataSnapshot.child("Tuition Image").getValue().toString();
Picasso.get().load(image).placeholder(R.drawable.camera).into(TuitionImage);
}
}
@Override
public void onCancelled(DatabaseError databaseError)
{
}
});
最佳答案
解决方案:
首次上传图片:
private void uploadImageAndGetURL(String ImageId) {
final StorageReference filePath = storageImage.child(ImageId + ".jpg");
UploadTask uploadTask = filePath.putFile(imageUri);
uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
// Continue with the task to get the download URL
return filePath.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
downloadURL = task.getResult().toString();
storeDataToFirebase();
} else {
Toast.makeText(AddAdsActivity.this, "There has bean a problem in the database.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
然后上传数据:
private void storeDataToFirebase() {
String id = databaseAdvertisement.push().getKey();
Advertisement advertisement = new Advertisement(id, downloadURL, tuitioname, providername, providergender, tuitionaddress, tuitionyear, tuitioncontactnumber, tuitionemail, tuitionsubject, tuitionprice, tuitionclasssize);
databaseAdvertisement.child(id).setValue(advertisement)
.addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
Toast.makeText(AddAdsActivity.this, "Advertisement added successfully!", Toast.LENGTH_SHORT).show();
Intent ViewAdsIntent = new Intent(AddAdsActivity.this, ViewAdsActivity.class);
ViewAdsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(ViewAdsIntent);
finish();
loadingBar.dismiss();
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Toast.makeText(AddAdsActivity.this, "Failed to save the advertisement data. Please try again.", Toast.LENGTH_LONG).show();
loadingBar.dismiss();
}
});
}
就是这样。
关于java - .setValue 和 .addValueListener 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52008604/
我是 Android 编程和使用 Firebase 创建多人游戏的初学者。我正在考虑用户如何开始游戏的逻辑。 我想做的是当用户玩游戏的房间满了时显示Toast。但我想知道其他设备如何判断房间是否已满。
关于如何将图像保存在 Firebase 存储中,我遇到一些编码错误。并出现 2 个错误...有人可以帮助我...我的 logcat 如下... 1) 错误:找不到符号方法 setValue(Strin
我正在使用 Firebase 实时数据库创建一个应用。 onDataChange 内的代码变得越来越臃肿。例如,该部分内部有一些 if 语句,并且它是嵌套的。我想知道是否有更好的方式来组织这部分。我想
我是一名优秀的程序员,十分优秀!