I am new to Android development and trying to make an app but as soon as I open my app it shows the above error I have tried the previously mentioned ways in other questions Here is my main Activity
public class FreeCal extends AppCompatActivity {
public ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
mViewPager.setCurrentItem(1);
}
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch(position) {
case 0:
fragment = new MenuFragment();
break;
case 1:
fragment = new CalculatorFragment();
break;
case 2:
fragment = new MoreFragment();
break;
default:
fragment = new CalculatorFragment();
}
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}
}
**Here is my Fragment I think due to which the error is occuring.I am not able to understand what to do. The error is occuring due to the onCreate method of this CalculatorFragment.I think The error is related to container **
public class CalculatorFragment extends Fragment implements View.OnClickListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_calculator,container, false);
return view;
**Here is my onCreateMethod for the fragment**
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
final String string = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).getString("theme", "0");
switch ( string ) {
case "0": {
getActivity().setContentView(R.layout.fragment_calculator);
break;
}
case "1": {
getActivity().setContentView(R.layout.fragment_calculator_orange);
break;
}
}
this.z = getActivity().getSharedPreferences("calc_history", 0);
this.A = getActivity().getSharedPreferences("calc_mode", 0);
this.B = this.A.getBoolean("mode", false);
if (this.B) {
this.J = this.getString(R.string.screen_scientific);
} else {
this.J = this.getString(R.string.screen_standard);
}
this.l = getActivity().findViewById(R.id.txt_hint);
this.m = getActivity().findViewById(R.id.txt_out);
if (bundle != null) {
this.r = bundle.getDouble("ans");
this.s = bundle.getDouble("mreg");
this.v = bundle.getString("current_token");
this.n = bundle.getChar("lastkey");
this.t = new LinkedList <String>(Arrays.asList(bundle.getStringArray("input_tokens")));
this.m.setText(this.c(this.b(true)));
}
final Display defaultDisplay = getActivity().getWindowManager().getDefaultDisplay();
final Point point = new Point();
defaultDisplay.getSize(point);
final int y = point.y;
this.o = y / 9;
if (this.B && this.getResources().getConfiguration().orientation == 1) {
this.o = y / 12;
Here is the Logcat. I have tried methods provided in the previous questions
java.lang.IllegalArgumentException: No view found for id 0x7f09007b (com.kingslayer.freecal_allinonecalculator:id/container) for fragment CalculatorFragment{e145b35 #0 id=0x7f09007b android:switcher:2131296379:1}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
at