我正在以程序化的方式对屏幕亮度进行调整。但是我收到以下错误。我知道我必须将上下文发送到getwindow()。但我不知道怎么做?任何想法?
public void setScreenBrightness(float num)
{
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = num;
getWindow().setAttributes(lp);
}
ERROR:
05-10 00:31:50.726:E / AndroidRuntime(22345):致命异常:主要 05-10 00:31:50.726:E / AndroidRuntime(22345):java.lang.NullPointerException 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.uiu.brighteness.UIUBrightenessActivity.setScreenBrightness(UIUBrightenessActivity.java:89) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.uiu.brighteness.VerticalSeekBar.onTouchEvent(VerticalSeekBar.java:82) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.View.dispatchTouchEvent(View.java:3933) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1877) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1211) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.app.Dialog.dispatchTouchEvent(Dialog.java:674) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1852) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2382) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.view.ViewRoot.handleMessage(ViewRoot.java:2010) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.os.Handler.dispatchMessage(Handler.java:99) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.os.Looper.loop(Looper.java:150) 05-10 00:31:50.726:E / AndroidRuntime(22345):在android.app.ActivityThread.main(ActivityThread.java:4385) 05-10 00:31:50.726:E / AndroidRuntime(22345):at java.lang.reflect.Method.invokeNative(Native Method) 05-10 00:31:50.726:E / AndroidRuntime(22345):at java.lang.reflect.Method.invoke(Method.java:507) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:849) 05-10 00:31:50.726:E / AndroidRuntime(22345):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607) 05-10 00:31:50.726:E / AndroidRuntime(22345):at dalvik.system.NativeStart.main(Native Method)