【发布时间】:2012-04-24 05:45:18
【问题描述】:
我有一个非常奇怪的问题。我有这个包含两个规则的过程对象。现在我想用 for 循环循环出这些规则并返回 1 条规则。但我总是得到空值。看起来他正在跳过 if 语句,直接进入我的 return null 部分。
第一条规则的名称是年龄,另一条规则的名称是意外。我已经在此处包含了该方法。
我的日志正在回馈:
规则名称:“年龄”和变量:“事故”并且为真?:“假”
rulename: 'accidents' and variable: 'accidents' and is true ?: 'true'
private Rule searchRule(String ruleName)
{
List<Rule> test = this.procedureObject.getRules();
for(Rule rule : test)
{
Log.d("debug", "rulename: '" + rule.getName() + "' and variable: '"+ruleName+"' and is true ?: '"+rule.getName().equalsIgnoreCase(ruleName)+"'");
if(rule.getName().equalsIgnoreCase(ruleName))
{
return rule;
}
}
return null;
}
编辑:现在可以使用了。
我只是在调用代码中更改了这个:
Rule makeRule = RuleFactory.getNewRuleClassNameInstance(this.searchRule(ref2.getName()).getClass().getSimpleName());
到:
Rule foundRule = this.searchRule(ref2.getName());
Rule makeRule = RuleFactory.getNewRuleClassNameInstance(foundRule.getClass().getSimpleName());
然后它突然起作用了。
【问题讨论】:
-
确实看起来应该执行条件块。所以我们可以 100% 确定哪个正在运行,可能会在每个
return之前抛出一个日志语句(你有没有在调试器中单步执行?)。 -
您的代码没有任何问题。只需正确调试您的代码,以便检查您的日志语句执行情况。或者可能不同步..!
-
@MichaelBurr 是的,我一步一步地通过调试器。这真是奇怪的行为..
-
请显示调用代码,并在
if语句内添加日志记录。 -
@VinceV.:这并没有显示您如何在调用代码中使用结果。我相信该方法正在被调用 - 但我也很容易相信您错误地使用了结果。
标签: java android android-2.2-froyo