SetActivityMain works fine, but Show_Soundfile_List doesn't work because ListView isn't found and results in lv = null (if I'm correct).
Any idea why this is? Both have pretty much the same code & setup so I'm not sure why one is able to find it's ListView but not the other one.
Error code:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Code:
public void SetActivityMain() {
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.lv_alarms);
Button btn = (Button) findViewById(R.id.btn_new_alarm);
lv.setAdapter(new MyListAdapter_alarm(MainActivity.this, R.layout.list_alarms, alarms));
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NewAlarm(new Alarm());
}
});
}
void Show_Soundfile_List(final Alarm alarm) {
setContentView(R.layout.activity_soundfile_list);
ListView lv = (ListView) findViewById(R.id.lv_soundfiles);
Button btn = (Button) findViewById(R.id.btn_list_soundfile);
lv.setAdapter(new MyListAdapter_SoundFile(MainActivity.this, R.layout.list_soundfiles, soundfiles, alarm));
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditAlarm(alarm);
}
});
}