从通过singleSnapshot获取值的类对象使用getter函数时出现问题。Android,Java
我正在通过单个快照(存储在“广告”类对象中)从firebase提取用户输入的数据 product name的getter方法有效,但是getProductDescription()返回空值,我不知道为什么。i、 e,文本视图14已填充,而不是文本视图15 数据已在firebase控制台中正确上载从通过singleSnapshot获取值的类对象使用getter函数时出现问题。Android,Java,java,android,firebase,getter,Java,Android,Firebase,Getter,我正在通过单个快照(存储在“广告”类对象中)从firebase提取用户输入的数据 product name的getter方法有效,但是getProductDescription()返回空值,我不知道为什么。i、 e,文本视图14已填充,而不是文本视图15 数据已在firebase控制台中正确上载 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_new, container, false);
// productImage = (ImageView) v.findViewById(R.id.imageView4);
//productDescription = (TextView) v.findViewById(R.id.textView15);
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference reff;
productName = v.findViewById(R.id.textView14);
productDescription = v.findViewById(R.id.textView15);
reff = database.getReference();
reff.child("Advertisement").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
DataSnapshot snapshot = dataSnapshot;
Advertisement advertisement = snapshot.child("adv").getValue(Advertisement.class);
productName.setText(advertisement.getProductName());
productDescription.setText( advertisement.getProductDescription());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return v;
}
这是firebase控制台
请帮我纠正这个问题。这让我很烦,尤其是因为一个函数工作,另一个不工作,而且它们属于同一个对象。问题已经得到纠正。。我没有给数据库添加一个广告类对象,而是一个哈希映射值(那个代码位在另一个java文件中,我完全没有考虑)。这是一个有趣的(对我来说也是愚蠢的)错误,但对我的第一个问题并不后悔 问题已得到纠正。。我没有给数据库添加一个广告类对象,而是一个哈希映射值(那个代码位在另一个java文件中,我完全没有考虑)。这是一个有趣的(对我来说也是愚蠢的)错误,但对我的第一个问题并不后悔 请添加您的
广告
类的内容。我现在已添加..请添加您的广告
类的内容。我现在已添加。。
package in.revmeup.revmeup;
import androidx.annotation.Keep;
@Keep
public class Advertisement {
private String productName;
private String productDescription;
private String productImageUrl;
public Advertisement(String productDescription)
{
this.productName=productName;
this.productImageUrl=productImageUrl;
this.productDescription=productDescription;
}
public Advertisement()
{
}
@Override
public String toString() {
return "Advertisement{" +
"product_Name='" + productName + '\'' +
", product_Image_URL='" + productImageUrl + '\'' +
", product_Description='" + productDescription +
'}';
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDescription() {
return productDescription;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
public String getProductImageUrl() {
return productImageUrl;
}
public void setProductImageUrl(String productImageUrl) {
this.productImageUrl = productImageUrl;
}
}