I have this code:
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = databaseHelper.getAgendaToEdit(id);
Intent intent = new Intent(view.getContext(), EditAgendaActivity.class);
cursor.moveToFirst();
intent.putExtra("id", cursor.getString(0));
startActivity(intent);
}
});
and error is:
java.lang.InstantiationException: can't instantiate class com.zeroe.EditAgendaActivity; no empty constructor
The goal is to just start a new activity when clicking an item in the list. I am calling this method from my main activity, which
list
is from as well. I assume the issue is coming from the fact that I am not getting the context from where my ListView is. Problem is it should be working because I am providing the correct context, at least I am assuming. ANy help would be much appreciated.
If anyone needs me to clarify, please let me know and I will do so right away.
Your
Activitysubclasses all need a default constructor. EvidentlyEditAgendaActivitydoes not have one. That’s where the problem lies, and not in the code that you posted.Generally, you should only have a default (no-arg) constructor for an
Activitysubclass or no constructor at all (and let the compiler generate a no-arg constructor for you).