I got this error when compiling the code below. Android studio also warned that Fragment is only supported at API level 11 and above.
Error:(16, 21) error: no suitable method found for add(int,ForecastFragment)
method FragmentTransaction.add(int,Fragment,String) is not applicable
(actual and formal argument lists differ in length)
method FragmentTransaction.add(int,Fragment) is not applicable
(actual argument ForecastFragment cannot be converted to Fragment by method invocation conversion)
method FragmentTransaction.add(Fragment,String) is not applicable
(actual argument int cannot be converted to Fragment by method invocation conversion)
Code:
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();
}
}
public class ForecastFragment extends Fragment {
private static final String TAG = ForecastFragment.class.getSimpleName();
private ArrayAdapter<String> mForecastAdapter;
public ForecastFragment() {
}