多くのユーザーから NullPointerException が発生しましたが、問題が何であるかを特定できません。次の行でスローされます。
((Button)findViewById(R.id.speakEnglishButton)).setText("");
何が問題なのかわかりません。ボタンはその ID で存在し、正常にコンパイルされ、エミュレーターと 2 つのデバイスで正常に動作しますが、これに関するユーザーの開発者コンソールに約 100 ほどのエラーが投稿されています。バージョン。
onResume を詳しく見てみましょう:
@Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean isButtonLabelsEnabled = sp.getBoolean("isButtonLabelsEnabled", false);
if (!isButtonLabelsEnabled)
{
((Button)findViewById(R.id.speakEnglishButton)).setText("");
((Button)findViewById(R.id.speakFrenchButton)).setText("");
((Button)findViewById(R.id.speakSpanishButton)).setText("");
((Button)findViewById(R.id.speakGermanButton)).setText("");
((Button)findViewById(R.id.speakItalianButton)).setText("");
}
else
{
((Button)findViewById(R.id.speakEnglishButton)).setText(getString(R.string.btnLblEnglish));
((Button)findViewById(R.id.speakFrenchButton)).setText(getString(R.string.btnLblFrench));
((Button)findViewById(R.id.speakSpanishButton)).setText(getString(R.string.btnLblSpanish));
((Button)findViewById(R.id.speakGermanButton)).setText(getString(R.string.btnLblGerman));
((Button)findViewById(R.id.speakItalianButton)).setText(getString(R.string.btnLblItalian));
}
}
基本的に、保存された設定のブール値をチェックするだけで、その値に応じて、ボタンにラベルを設定するか、空白に設定します。
誰でもアドバイスできますか?
ありがとう