In activity_layout.xml main I add a fragment :
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.example.pack2.t9ahbin.FragA"
android:id="@+id/fragment"
android:layout_weight="1"
/>
and in the Oncreate of Class FragA :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag1, container, false);
return v;
}
in activity_layout.xml i add a button and set on click listener to it so when i click on it the fragment must be removed, but it didn't :
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragA fragA ;
fragA = (FragA) getFragmentManager().findFragmentById(R.id.fragment);
getFragmentManager().beginTransaction().remove(fragA).commit();
}
});
when i click on it i got this error :
>java.lang.NullPointerException at android.app.BackStackRecord.run(BackStackRecord.java:653)