Note that there are some explanatory texts on larger screens.

plurals
  1. PONPE when calling setVisibility with ViewFlipper
    text
    copied!<p>I have a ViewFlipper with the following XML Note that this is all contained inside a RelativeLayout</p> <pre><code>&lt;ViewFlipper android:id="@+id/flipperIdentView" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;include layout="@layout/identification_face"/&gt; &lt;include layout="@layout/identification_rfid"/&gt; &lt;include layout="@layout/identification_voice"/&gt; &lt;include layout="@layout/identification_pill_dispense"/&gt; &lt;/ViewFlipper&gt; &lt;LinearLayout android:id="@+id/linear_button_view" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="bottom" android:orientation="vertical" &gt; &lt;include android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/test_buttons" android:gravity="center" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The LinearLayout has the ID of "linear_button_view". Now inside my fragment, I have code to determine the flipping, and that all works. The problem is, that when I get to index 3 of the flipper, I want to hide this layout. All I should have to do is create a field with this ID, and then setVisibility to View.Gone. But I am throwing a NPE when I try to do this. </p> <p>Inside the class I have a:</p> <pre><code>private View buttonView; </code></pre> <p>Inside my onCreateView, I have the following code</p> <pre><code>View v = inflater.inflate(R.layout.pilltransferflipper, container, false); buttonView = v.findViewById(R.id.linear_button_view); </code></pre> <p>This is my method that controls flipper, and is responsible for hiding the view.</p> <pre><code>private void nextState() { flipperIndex++; if (flipperIndex &gt;= flipperPillTransfer.getChildCount()) { MainActivity activity = (MainActivity) getActivity(); activity.stateChange(State.SESSIONFINISHED); } else { flipperPillTransfer.showNext(); Log.d(TAG, "FLIPPER INDEX: " + flipperIndex); if(flipperIndex == 3) { buttonView.setVisibility(View.GONE); } } } </code></pre> <p>When I put a Log.d message inside the flipperIndex condition, It is returned fine, it seems that the issue is the buttonView.setVisibility part of things. Keep in mind, I am using fragments, so some methods that are available in the main activity may not be available to me. Thanks!</p> <h1> Here is the logCat</h1> <pre><code>09-26 10:05:54.381: D/PillTransferFragment(1719): FLIPPER INDEX: 3 09-26 10:05:54.381: D/AndroidRuntime(1719): Shutting down VM 09-26 10:05:54.381: W/dalvikvm(1719): threadid=1: thread exiting with uncaught exception (group=0x40c2b300) 09-26 10:05:54.381: E/AndroidRuntime(1719): FATAL EXCEPTION: main 09-26 10:05:54.381: E/AndroidRuntime(1719): java.lang.NullPointerException 09-26 10:05:54.381: E/AndroidRuntime(1719): at com.example.android.fragments.PillTransferFragment.nextState(PillTransferFragment.java:107) 09-26 10:05:54.381: E/AndroidRuntime(1719): at com.example.android.fragments.PillTransferFragment.onClick(PillTransferFragment.java:64) 09-26 10:05:54.381: E/AndroidRuntime(1719): at android.view.View.performClick(View.java:4084) </code></pre>
 

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