Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy setVisibility causes NullPointerException?
    primarykey
    data
    text
    <p>I have the following:</p> <pre><code>private OnItemSelectedListener CommentCodeListener = new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { Log.i(LogTAG, "spinner selection: "+ position); LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view2=inflater.inflate(R.layout.commentdialog, null); CheckBox CommentPaper = (CheckBox) view.findViewById(R.id.CommentPaper); EditText CommentField = (EditText) view.findViewById(R.id.CommentOtherField); String[] arr = getResources().getStringArray(R.array.CommentCodeListValues); String CommentCode = arr[position]; int CommentCodeInt = Integer.parseInt(arr[position]); Log.i(LogTAG, "spinner selection (int): "+ CommentCodeInt); CommentPaper.setVisibility(View.GONE); CommentField.setVisibility(View.GONE); if( (CommentCodeInt &gt;= 21 &amp;&amp; CommentCodeInt &lt;= 31) || CommentCodeInt == 41 ) { Log.i(LogTAG, "set CommentPaper visible"); CommentPaper.setVisibility(View.VISIBLE); } if( (CommentCodeInt &gt;=22 &amp;&amp; CommentCodeInt &lt;=33) || (CommentCodeInt &gt;= 35 &amp;&amp; CommentCodeInt &lt;=36 ) || (CommentCodeInt &gt;= 42 &amp;&amp; CommentCodeInt &lt;=43 ) ) { Log.i(LogTAG, "set CommentPaper visible"); } if( CommentCodeInt &gt;=41 &amp;&amp; CommentCodeInt &lt;=43 ) { Log.i(LogTAG, "set CommentField visible"); CommentField.setVisibility(View.VISIBLE); } } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { Log.i(LogTAG, "nothing selected"); } }; </code></pre> <p>The layout: </p> <pre><code> &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" &gt; &lt;Spinner android:id="@+id/CommentCode_spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;EditText android:id="@+id/MultiLineComment" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:hint="@string/commentLabel" android:inputType="textMultiLine" android:lines="3" android:scrollbars="vertical" &gt; &lt;/EditText&gt; &lt;EditText android:id="@+id/CommentOtherField" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:hint="@string/commentLabel" android:visibility="visible" &gt; &lt;/EditText&gt; &lt;CheckBox android:id="@+id/CommentPaper" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/reportCheckBox" android:visibility="visible" /&gt; &lt;Button android:id="@+id/AddCommentButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/okButton" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Please note, that the layout above (commentdialog.xml) is a Dialog.</p> <p>The CommentCodeListener is called when I select something with a spinner. Everything works when setVisibility is commented. I have tried with </p> <ul> <li><code>CheckBox CommentPaper = (CheckBox) findViewById(R.id.CommentPaper);</code></li> <li><code>CheckBox CommentPaper = (CheckBox) view.findViewById(R.id.CommentPaper);</code></li> <li><code>CheckBox CommentPaper = (CheckBox) view2.findViewById(R.id.CommentPaper);</code></li> </ul> <p>but no luck.</p> <p>What am I missing?</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.
    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