我的程序中有问题。 我将给我的开关CheckedChangeListener并成为一个NullPointerException :( 在第37行,它发生了。 请帮帮我:)请不要谴责我的英语,我住在德国...... 我的代码是:
private ActionBar actionBar;
TabActivity tabActivity;
private TabHost tabHost;
private TabHost.TabSpec theSpec;
private Intent intent;
private Switch statusCall, statusSMS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getActionBar();
actionBar.hide();
tabHost = getTabHost();
statusCall = (Switch)findViewById(R.id.statuscall);
statusSMS = (Switch)findViewById(R.id.statussms);
statusCall.setOnCheckedChangeListener(this);
statusSMS.setOnCheckedChangeListener(this);
// BlitzLeuchte-Tab
intent = new Intent(this, DieBlitzLeuchte.class);
theSpec = tabHost.newTabSpec("einleitung")
.setIndicator("Einleitung/Hintergrund")
.setContent(intent);
tabHost.addTab(theSpec);
// Einstellungs-Tab
intent = new Intent(this, Einstellungen.class);
theSpec = tabHost.newTabSpec("einstellungen")
.setIndicator("Einstellungen")
.setContent(intent);
tabHost.addTab(theSpec);
checkFlashLightAvailable();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void checkFlashLightAvailable() {
if (getBaseContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA_FLASH)) {
Toast toast = Toast.makeText(getBaseContext(),
"Erfolgreich gestartet!", Toast.LENGTH_LONG);
toast.show();
} else {
Toast noFlashLight = Toast.makeText(getBaseContext(),
"Es wurde kein Flash-Light gefunden!", Toast.LENGTH_LONG);
noFlashLight.show();
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch(buttonView.getId()) {
case R.id.statuscall:
boolean checkedCall = ((Switch) buttonView).isChecked();
CallReceiver.CallReceiverStatus=checkedCall;
break;
case R.id.statussms:
boolean checkedSMS = ((Switch) buttonView).isChecked();
SMSReceiver.broadCastReceiverStatus=checkedSMS;
}
}
}