【发布时间】:2012-04-19 07:23:31
【问题描述】:
您好,我需要检查两个变量的值是否为空。如果它们不为空,我必须使文本视图可见。同样,我编写了以下代码
if (offer.Price() != null ) {
if(offer.getName() !=null)
{
Price.setVisibility(View.VISIBLE);
Price.setText(offer.getName()+" Price: $"+offer.getPrice());
}
}
但它不起作用。即即使变量值为 null 并且 textview 中的文本显示为“null Price: $null”,textview 也是可见的。首先我尝试使用以下代码。但这也是不工作
if (offer.getPrice() != null && offer.getName() !=null) {
Price.setVisibility(View.VISIBLE);
Price.setText(offer.getName()+" Price: $"+offer.getPrice());
}
请帮我解决它....
【问题讨论】:
-
这是什么意思:offer.Price()?当您阅读此内容时修复它:docs.oracle.com/javase/tutorial/java/nutsandbolts/… 和 docs.oracle.com/javase/tutorial/java/javaOO/constructors.html
-
它的方法不是变量.. 如果它们“返回 NULL;”它们将等于 null。
-
哦..这是我的错误..那是一个函数..offer.price() 是一个错误。它是 offer.getPrice() 而我的问题是 if(offer.getPrice() !=null) 条件不起作用。