Note that there are some explanatory texts on larger screens.

plurals
  1. POSet spinner within custom dialog
    primarykey
    data
    text
    <p>I'm getting a NullPointerException while attempting to create a Spinner within a dialog and can't seem to debug it because the code looks solid. Wonder if anyone else has any idea. Any help is greatly appreciated.</p> <pre><code> protected Dialog onCreateDialog(int id) { Dialog dialog; switch(id) { case DIALOG_SEND_PM: Spinner spinner = (Spinner)findViewById(R.id.pm_server); ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this, R.array.server_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new MyOnItemSelectedListener()); dialog = new Dialog(PM.this); dialog.setContentView(R.layout.send_pm_dialog); dialog.setTitle(R.string.send_pm); pmMessage = (EditText) dialog.findViewById(R.id.send_pm_box); Button sendPm = (Button) dialog.findViewById(R.id.send_pm_button); sendPm.setOnClickListener(PM.this); break; default: dialog = null; } </code></pre> <p>I get the exception at adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); I changed the context to MyClass.this and the exception moved down to the next line, which confuses me. I'm wondering if it is the adapter having a null value but I call everything the same way I have before while not in a dialog.</p> <p>Relevant XML data:</p> <pre><code>&lt;LinearLayout&gt; &lt;TextView/&gt; &lt;LinearLayout&gt; &lt;TextView/&gt; &lt;EditText/&gt; &lt;TextView/&gt; &lt;Spinner android:id="@+id/pm_server" android:layout_height="fill_parent" android:layout_width="wrap_content" android:background="@drawable/yblueborder" android:textColor="#ABABAB"/&gt; &lt;/LinearLayout&gt; &lt;Button/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Edited out the rest of the data so it wouldn't take up too much space.</p>
    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.
 

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