Attached are two fragments. The second is identical in structure to the first. Called from the menu drover. The first and second open without problems. But as soon as I add a button click handler in the second when opening a fragment with this button, the application crashes. Fragment code: public class FragmentTanks extends Fragment {
private OnFragmentInteractionListener mListener; public static final double pi = 3.1415926535; Animation anim_show; Animation anim_hide; //Π Π°Π·Π΄Π΅Π» ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΡ Layout //**************************************** LinearLayout L_tanks_flow_wash; LinearLayout L_tanks_volume_solution; //Π Π°Π·Π΄Π΅Π» ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΡ Button //**************************************** Button btn_tanks_flow_wash; Button btn_tanks_flow_wash_calculate; Button btn_tanksF_volume_solution; Button L_tanks_volume_solution_calculate; // Π Π°Π·Π΄Π΅Π» ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΡ EditText ΠΈ Spinner //**************************************** EditText et_tanksF_diameter; EditText et_tanks_angle_spray; EditText et_tanks_current_flow; Spinner sp_tanks_pollution_level; EditText et_tanks_estimated_flow; EditText et_tanksV_diameter; EditText et_tanks_cone_height; EditText et_tanks_cylinder_height; EditText et_tanks_volume_solution; public FragmentTanks() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_tanks, container, false); anim_show = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.anim_show); anim_hide = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.anim_hide); //region ΠΠΎΡΠΎΠΊ Π½Π° ΠΌΠΎΠΉΠΊΡ ΡΠ°Π½ΠΊΠ° //Π Π°Π·Π΄Π΅Π» ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ Layout //**************************************** L_tanks_flow_wash = (LinearLayout) rootView.findViewById(R.id.L_tanks_flow_wash); // Π Π°Π·Π΄Π΅Π» ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ Button //**************************************** btn_tanks_flow_wash = (Button) rootView.findViewById(R.id.btn_tanks_flow_wash); btn_tanks_flow_wash_calculate = (Button) rootView.findViewById(R.id.btn_pipes_flowD_calculate); // Π Π°Π·Π΄Π΅Π» ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ EditText ΠΈ Spinner //**************************************** et_tanksF_diameter = (EditText) rootView.findViewById(R.id.et_tanksF_diameter); et_tanks_angle_spray = (EditText) rootView.findViewById(R.id.et_tanks_angle_spray); et_tanks_current_flow = (EditText) rootView.findViewById(R.id.et_tanks_current_flow); sp_tanks_pollution_level = (Spinner) rootView.findViewById(R.id.sp_tanks_pollution_level); et_tanks_estimated_flow = (EditText) rootView.findViewById(R.id.et_tanks_estimated_flow); btn_tanks_flow_wash.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (btn_tanks_flow_wash.getVisibility() == View.VISIBLE) { hide(L_tanks_flow_wash); } else { show(L_tanks_flow_wash); } } }); btn_tanks_flow_wash_calculate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getActivity(), "ΠΠΎΡΠΌ!", Toast.LENGTH_LONG).show(); } }); //endregion return rootView; } }
Fragment markup:
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context="ru.zets_swe.calculator.fragments.FragmentTanks"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="6dp"> <Button android:id="@+id/btn_tanks_flow_wash" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/tv_tanks_the_flow_to_the_sink_tanks" /> <LinearLayout android:id="@+id/L_tanks_flow_wash" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:visibility="visible"> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:shrinkColumns="0" android:stretchColumns="*" android:textAlignment="center"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center"> <TextView style="@style/table_text" android:text="@string/tv_tanks_diameter" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_angle_spray" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_current_flow" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_pollution_level" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_estimated_flow" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/et_tanksF_diameter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <EditText android:id="@+id/et_tanks_angle_spray" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <EditText android:id="@+id/et_tanks_current_flow" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <!-- <EditText android:id="@+id/et_tanks_pollution_level" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:editable="true" android:ems="1" android:enabled="false" android:inputType="number" />--> <Spinner android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/sp_tanks_pollution_level" android:layout_gravity="center_horizontal" /> <EditText android:id="@+id/et_tanks_estimated_flow" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:editable="true" android:ems="1" android:enabled="false" android:inputType="number" /> </TableRow> </TableLayout> <Button android:id="@+id/btn_tanks_flow_wash_calculate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@color/colorAccent" android:text="@string/btn_text_calculate" /> </LinearLayout> <Button android:id="@+id/btn_tanksF_volume_solution" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/tv_tanks_volume_of_the_solution_in_the_tank" /> <LinearLayout android:id="@+id/L_tanks_volume_solution" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:visibility="gone"> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:shrinkColumns="0" android:stretchColumns="*" android:textAlignment="center"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center"> <TextView style="@style/table_text" android:text="@string/tv_tanks_diameter" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_cone_height" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_cylinder_height" /> <TextView style="@style/table_text" android:text="@string/tv_tanks_volume_solution" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/et_tanksV_diameter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <EditText android:id="@+id/et_tanks_cone_height" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <EditText android:id="@+id/et_tanks_cylinder_height" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="1" android:hint="0" android:inputType="number|numberDecimal" /> <EditText android:id="@+id/et_tanks_volume_solution" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:editable="true" android:ems="1" android:enabled="false" android:inputType="number" /> </TableRow> </TableLayout> <Button android:id="@+id/L_tanks_volume_solution_calculate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@color/colorAccent" android:text="@string/btn_text_calculate" /> </LinearLayout> </LinearLayout> </ScrollView> If you remove btn_tanks_flow_wash_calculate, then everything works. Where could the problem be?