我是android开发的初学者,确切地说,是在开发中。我开始学习为android开发,并想做这个练习:编写一个小程序将亮度更改为三个不同的级别:current-low-high。在编写完我的代码和所有内容之后,我无法让它运行,每次运行它时,FORCE CLOSE 都会出现。请帮助我找出我的错误。:(
我的代码:
package com.dummies.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
// MY BRIGHTNESS VARIABLES
WindowManager.LayoutParams lp = getWindow().getAttributes();
float fb = lp.screenBrightness;
float lb = 0;
float hb = 1;
//////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// MY CODE FROM HERE DOWN
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(lp.screenBrightness==fb) {
lp.screenBrightness=lb;
getWindow().setAttributes(lp);
}
if(lp.screenBrightness==lb){
lp.screenBrightness=hb;
getWindow().setAttributes(lp);
}
if(lp.screenBrightness==hb){
lp.screenBrightness=fb;
getWindow().setAttributes(lp);
}
}
} );
//////////////////////////////////////////////
}
}
请帮助我:(我需要做什么才能让它工作?