customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(),
"The custom preference has been clicked",
Toast.LENGTH_LONG).show();
SharedPreferences customSharedPreference =
getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor =
customSharedPreference
.edit();
editor.putString("myCustomPref",
"The preference has been clicked");
editor.commit();
return true;
}
});
上記のコードは正常に動作します
しかし、以下を使用しようとすると
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent int1 = new Intent(getBaseContext(),
termandcondition.class);
getBaseContext().startActivity(int1);
return true;
}
});
エラーが発生します。実装方法を教えてください
ログ
12-10 15:34:20.405: E/AndroidRuntime(377): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adodis.taxmann/com.adodis.taxmann.termandcondition}: java.lang.NullPointerException Error is coming