[英]Null value when trying to retrieve from other class
somehow my mind is not working and mild fever didn't help. 不知何故,我的思绪不起作用,轻微的发烧没有帮助。
I have the following code, batteryLevel here shows the correct value - 50. 我有以下代码,batteryLevel在这里显示正确的值 - 50。
public class AlarmEventService extends Service {
static String batteryLevel;
...
int level = intent.getIntExtra("level", 0);
batteryLevel = String.valueOf(level);
Log.i(APP_TAG, batteryLevel);
}
Why in my outside call when I get value of AlarmEventService.batteryLevel the value is null? 当我获得AlarmEventService.batteryLevel的值时,为什么在我的外部调用中值为null?
public class AlarmEventReceiverWake extends BroadcastReceiver {
...
Log.i(APP_TAG, "Battery Level " + AlarmEventService.batteryLevel);
}
From what you have presented of the code, there is no reason why it shouldnt work as expected. 根据您提供的代码,没有理由说它不能按预期工作。 It may be possibile that:
它可能是这样的:
Make sure that the statement: 确保声明:
batteryLevel = String.valueOf(level);
is actually being called before 实际上是在被召唤之前
Log.i(APP_TAG, "Battery Level " + AlarmEventService.batteryLevel);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.