Main.java ファイルから textView を取得しようとしていますが、通知をクリックすると、それが出力されます。そのために sharedPreferences を使用することを知っています。私はそれをしました。ただし、NullPointerException をスローし続けますが、NotificationPage.java クラスで呼び出す必要があるすべてを呼び出したので、正確に何が間違っているのかわかりません。どんな助けでも大歓迎です。
これは私の NotificationPage.java クラスです
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class NotificationPage extends Activity {
SharedPreferences sp;
SharedPreferences.Editor edit;
TextView arrival;
TextView notifdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification);
notifdate=(TextView)findViewById(R.id.textView5);
arrival=(TextView)findViewById(R.id.textView4);
sp=getSharedPreferences(arr, MODE_PRIVATE);
edit=sp.edit();
sp.getString(arr, null);
edit=sp.edit();
edit.putString(arr,sp.getString(arr,null));
notifdate.setText("Hey!" + sp.getString(arr,null));
edit.apply();
}
これは、他の Java ファイルから共有設定を取得するコード行です。
arr=arrival.getText().toString();
sp=getSharedPreferences(arr,MODE_PRIVATE);