Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException in ListView inside a LinearLayout
    primarykey
    data
    text
    <p>When I attempt to run this particular activity in my Android app, I get a NullPointerException at the line (appears as a single line in Eclipse) which I've marked with an arrow.</p> <p>This activity uses a linear layout, and features a ListView in one of the linear, I guess, 'segments'. I'm using the same ListView code in other activities that only have a ListView in the activity, so those classes extend ListActivity.</p> <p>In the code shown below, I'm just extending Activity as usual, since if I extend ListActivity here, I get an error stating that I must have a ListView whose attribute is 'android.R.id.list', which as you can see, there is.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_book_event); final ListView lv = (ListView) findViewById(android.R.id.list); lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.cities))); &lt;--- final Spinner s = (Spinner) findViewById(R.id.spinner); ArrayAdapter&lt;CharSequence&gt; aa = new ArrayAdapter&lt;CharSequence&gt;(this, R.array.noSeats, android.R.layout.simple_spinner_item); aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(aa); s.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { noOfSeats = s.getSelectedItemPosition(); noOfSeats = noOfSeats + 1; } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { } }); } </code></pre> <p>What's the problem here? The other ListViews access the string array just fine, so how is this different?</p> <p>EDIT: Added stack trace</p> <pre><code>04-05 21:30:00.282: E/AndroidRuntime(12791): FATAL EXCEPTION: main 04-05 21:30:00.282: E/AndroidRuntime(12791): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.event_booker/com.example.event_booker.BookEvent}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.os.Handler.dispatchMessage(Handler.java:99) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.os.Looper.loop(Looper.java:130) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread.main(ActivityThread.java:3701) 04-05 21:30:00.282: E/AndroidRuntime(12791): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 21:30:00.282: E/AndroidRuntime(12791): at java.lang.reflect.Method.invoke(Method.java:507) 04-05 21:30:00.282: E/AndroidRuntime(12791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 04-05 21:30:00.282: E/AndroidRuntime(12791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 04-05 21:30:00.282: E/AndroidRuntime(12791): at dalvik.system.NativeStart.main(Native Method) 04-05 21:30:00.282: E/AndroidRuntime(12791): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ListActivity.onContentChanged(ListActivity.java:243) 04-05 21:30:00.282: E/AndroidRuntime(12791): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:230) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.Activity.setContentView(Activity.java:1657) 04-05 21:30:00.282: E/AndroidRuntime(12791): at com.example.event_booker.BookEvent.onCreate(BookEvent.java:22) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-05 21:30:00.282: E/AndroidRuntime(12791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 04-05 21:30:00.282: E/AndroidRuntime(12791): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload