APP crash: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference

I am extremely new to programming so your help will be greatly appreciated and this is the first time I am asking for help here so hope i am doing it right. I am trying to create a simple notes taking section in an app but am getting the following error: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference:

Here is the code:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

et_memo = (EditText) findViewById(R.id.et_memo);

b_clear = (Button) findViewById(R.id.b_clear);

b_save = (Button) findViewById(R.id.b_save);

SharedPreferences preferences = getSharedPreferences("PREFS", 0);

memo = preferences.getString("memo","");

et_memo.setText(memo);

b_clear.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)...

Read More »

By: StackOverFlow - Saturday, 21 July

Related Posts