android中提示:Cannot make a static reference to the non-static method getSystemService(Strin) from the type 或者 Non-static method ‘getSystemService(java.lang.String)’ cannot be referenced from a static context解决方案
1.1 问题描述
今天在进行android编程的时候,提示:Non-static method ‘getSystemService(java.lang.String)’ cannot be referenced from a static context。
下面我先将我的代码展现出来(代码测试是在 < Android API 32 Platform > 中):
private void BatteryRemainingEnergy(TextView tv_cell) {
BatteryManager mBatteryManager =
// error: Non-static method 'getSystemService(java.lang.String)' cannot be referenced from a static context
(BatteryManager)Context.getSystemService(Context.BATTERY_SERVICE);
Long energy = mBatteryManager.getLongProperty(BatteryManager