我正在尝试获取 Android 中的屏幕亮度。
场景是这样的,A类调用B类的函数:
A类:
if(condition is true){
ClassB.function();
}
B类:
function(){
WindowManager.LayoutParams screenBrightness = getWindow()
.getAttributes();
screenBrightness.screenBrightness = 1;
screenBrightness.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
screenBrightness.flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
screenBrightness.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
getWindow().setAttributes(screenBrightness);
}
收到的异常如下:
06-15 13:36:30.476: E/AndroidRuntime(8873): FATAL EXCEPTION: main
06-15 13:36:30.476: E/AndroidRuntime(8873): java.lang.NullPointerException
06-15 13:36:30.476: E/AndroidRuntime(8873): at function(B.java:68)
06-15 13:36:30.476: E/AndroidRuntime(8873): at something.run(A.java:104)
06-15 13:36:30.476: E/AndroidRuntime(8873): at android.os.Handler.handleCallback(Handler.java:587)
06-15 13:36:30.476: E/AndroidRuntime(8873): at android.os.Handler.dispatchMessage(Handler.java:92)
06-15 13:36:30.476: E/AndroidRuntime(8873): at android.os.Looper.loop(Looper.java:130)
06-15 13:36:30.476: E/AndroidRuntime(8873): at android.app.ActivityThread.main(ActivityThread.java:3701)
06-15 13:36:30.476: E/AndroidRuntime(8873): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 13:36:30.476: E/AndroidRuntime(8873): at java.lang.reflect.Method.invoke(Method.java:507)
06-15 13:36:30.476: E/AndroidRuntime(8873): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
06-15 13:36:30.476: E/AndroidRuntime(8873): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
06-15 13:36:30.476: E/AndroidRuntime(8873): at dalvik.system.NativeStart.main(Native Method)
有没有人之前遇到过这个问题?