Note that there are some explanatory texts on larger screens.

plurals
  1. POFragment Tabs Strange Crashes
    primarykey
    data
    text
    <p>Does anyone know what to do with this Fragment Tabs Problem?</p> <p>I am a very novice programmer with not much experience, especially in the world of Android application developing. I recently started a project with fragment tabs and I find that when I try to access a object (for lack of a better word, but I mean like a TextView, Spinner, EditText, etc.) by something like</p> <pre><code>TextView textBox = (TextView) getView().findViewById(R.id.scouter_name_box); </code></pre> <p>the compiler finds no errors, but the app crashes. I have tried putting this line of code in a function, in the body of the fragment by itself (after onCreate()), and at the end of onCreate(). This doesn't help. The Error Log also doesn't say anything.</p> <p>Furthermore, when I comment out this line, the rest of the app runs seamlessly. The app doesn't have any other activities except MainActivity and the three tab Fragments.</p> <p>WHAT CAN I DO TO ACCESS THE TEXTVIEWS, SPINNERS, ETC?</p> <p>also, as I mentioned I am very new. If you need a better explanation please ask, and sorry if I don't understand what you are saying at first.</p> <p>We all have to start somewhere</p> <p>Please help, and Thank you in Advance</p> <p>Tab XML File:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/input_scouter_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:text="Scouter Name:" android:textSize="25sp" android:textStyle="bold" /&gt; &lt;Spinner android:id="@+id/choose_scouter_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/input_scouter_name" android:entries="@array/scouter_name_list" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>MainActivity Java File:</p> <pre><code>import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { // Declare Tab Variable Tab tab; ScoutingData ScoutData; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create the actionbar ActionBar actionBar = getActionBar(); // Hide Actionbar Icon actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(R.drawable.red_and_blue_frisbees); // Hide Actionbar Title actionBar.setDisplayShowTitleEnabled(true); // Create Actionbar Tabs actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create Home Tab tab = actionBar.newTab().setTabListener(new FragmentsTab0()); // Set Tab Title tab.setText("General"); actionBar.addTab(tab); // Create first Tab tab = actionBar.newTab().setTabListener(new FragmentsTab1()); // Set Tab Title tab.setText("Autonomous"); actionBar.addTab(tab); // Create Second Tab tab = actionBar.newTab().setTabListener(new FragmentsTab2()); // Set Tab Title tab.setText("Teleop"); actionBar.addTab(tab); // Create Third Tab tab = actionBar.newTab().setTabListener(new FragmentsTab3()); // Set Tab Title tab.setText("Endgame"); actionBar.addTab(tab); } } </code></pre> <p>Tab Java File:</p> <pre><code>import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; import android.widget.Spinner; public class FragmentsTab0 extends Fragment implements ActionBar.TabListener { private Fragment mFragment; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from tab0fragment.xml getActivity().setContentView(R.layout.tab0fragment); } public void onTabSelected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub mFragment = new FragmentsTab0(); // Attach tab0fragment.xml layout ft.add(android.R.id.content, mFragment); ft.attach(mFragment); } public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub // Remove tab0fragment.xml layout ft.remove(mFragment); } public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } //Heeere's the Problem Spinner scouterName = (Spinner) getView().findViewById(R.id.choose_scouter_name); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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