私は間違っているのか分かりません。私のアプリでは、提出時にテキストフィールドに入力された以前のパスワードを覚えているようにしています。共有設定を使って行われた研究から、変数がアプリケーションを再起動しても保存されます。私のコードのトップ:AndroidアプリのSharedPreferencesは私のことを覚えていますbutton
if (rememberSwitch.isChecked()) {
BT_debugger.showIt(fragmentName + ":rememberSwitch is ON");
SharedPreferences settings = context.getSharedPreferences(PASSVALUE, MODE_PRIVATE);
String rpass= settings.getString("rpassword","");
if (rpass!=null) {
voucherTextfieldEditText.setText(rpass);
} else {
voucherTextfieldEditText.setText("nono");
}
}
else {
BT_debugger.showIt(fragmentName + ":rememberSwitch is OFF");
// switchStatus.setText("Switch is currently OFF");
}
その後提出上の文字列を保存するために私のコード:
if (loadScreenNickname.length() > 1 && !loadScreenNickname.equalsIgnoreCase("none")) {
// before we launch the next screen...
if (!rememberSwitch.isChecked()) {
voucherTextfieldEditText.setText("");
}
if (rememberSwitch.isChecked()){
//voucherTextfieldEditText.setText("");
String pass = voucherTextfieldEditText.getText().toString();
BT_debugger.showIt(pass + ":CODE");
SharedPreferences settings = context.getSharedPreferences(PASSVALUE, MODE_PRIVATE);
settings.edit().putString("rpassword", pass).apply();
rememberSwitch.setChecked(true);
}
errormessageTextView.setVisibility(View.GONE);
errormessageTextView.invalidate();
//loadScreenObject(null, thisScreen);
try {
loadScreenWithNickname(loadScreenNickname);
foundIt = 1;
} catch (Exception ex){
Log.e ("eTutorPrism Error", "Caught this exception " + ex);
ex.printStackTrace();
}
break;
}
}
しかし残業、私は私の中にプラグインを実行セットはとき
public class AK_Voucher_access extends BT_fragment{
View thisScreensView = null;
String errormessage = "";
String errormessageTextColor = "";
String errormessageText = "";
String rememberTextText = "";
String rememberTextTextColor = "";
String voucherTextfieldPlaceholder = "";
String voucherTextfieldSecureTextEntry = "";
boolean voucherTextfieldSecureTextEntryBool = false;
String iphoneImage = "";
String ipadImage = "";
String errormessageInvalid = "";
String errormessageRemember = "";
private TextView errormessageTextView = null;
private EditText voucherTextfieldEditText = null;
private ImageView imageView = null;
private Button submitButton = null;
private Switch rememberSwitch = null;
private Drawable myHeaderImageDrawable = null;
private String alphaImage = "", pass;
private static BT_item screenObjectToLoad = null;
private static final String PASSVALUE = "value";
//private static final String appPassword = "appPassword";
Context context;
テキストフィールドを取得するために、 appこのエラーはlogcatに表示されます:
E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
at com.asfapp.ui.bt_plugins.AK_Voucher_access.onCreateView(AK_Voucher_access.java:210)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.asfapp, PID: 24771
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
at com.asfapp.ui.bt_plugins.AK_Voucher_access.onCreateView(AK_Voucher_access.java:210)
今回はコードに何が問題なのか分かりませんが、何か助けてください。