私はAndroid開発の初心者です。正確には、開発中です。私はAndroid向けの開発を学び始めていて、この演習を行いたいと思っていました。明るさを3つの異なるレベル(current-low-high)に変更する小さなプログラムを作成します。コードとすべてを記述した後、実行させることができません。実行するたびに、FORCECLOSEが表示されます。私のエラーを見つけるのを手伝ってください。:(
私のコード:
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);
}
}
} );
//////////////////////////////////////////////
}
}
私を助けてください:(それを機能させるために私は何をする必要がありますか?