I've got a problem when trying to run my app in Android Studio. I get a
FATAL EXCEPTION: main
more precisely there seems to be a problem at:
dancam.com.chords.ChordsListActivity.onCreate(ChordsListActivity.java:13)
which is:
setContentView(R.layout.activity_chords_list);
here is the ChordsListActivity class:
import android.app.ListActivity;
import android.os.Bundle;
public class ChordsListActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chords_list);
String[] accordi = new String[] {"Do maggiore", "Re maggiore", "Si maggiore"};
String[] note = new String[] {"note: Do, Mi, Sol", "note: La, Re, Fa#", "note: Fa#, Si, Re#"};
int[] immagini = new int[] {R.drawable.do_maggiore, R.drawable.re_maggiore, R.drawable.si_maggiore};
CustomListAdapter adapter = new CustomListAdapter(getApplicationContext(), accordi, note, immagini);
setListAdapter(adapter);
}
}
I was kinda able to solve it by extending Activity
instead of ListActivity
but then I cannot use the setListAdapter()
method.
I'd really appreciate if someone could help me fix the code!
please let me know if you need me to post the custom Adapter or any other file.
Edit: added the whole stack trace
FATAL EXCEPTION: main
Process: dancam.com.chords, PID: 3080
java.lang.RuntimeException: Unable to start activity ComponentInfo{dancam.com.chords/dancam.com.chords.ChordsListActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ListActivity.onContentChanged(ListActivity.java:243)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:398)
at android.app.Activity.setContentView(Activity.java:2166)
at dancam.com.chords.ChordsListActivity.onCreate(ChordsListActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)