I worked with fragments in android studio 1.0.1. Just as the network process is unsuitable in the main user interface, I moved my code to another class containing fragments. But what happened afterwards does not help me continue. the error that I get cannot be solved by the add(R.id.container, new com.sunshine.example.sunshine.app.Fragment).commit(); method add(R.id.container, new com.sunshine.example.sunshine.app.Fragment).commit(); here is the code snippet of my MainActivity class, but everything is fine with the Fragment class.
package com.sunshine.example.sunshine.app; import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction(). add(R.id.container, new ForecastFragment()).commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) {
source share