2

The import android.app.FragmentManager cannot be resolved. I downloaded the support libraries from SDK Manager. I have also set path for the jar files. Still this error persists.

package com.example.myfragments;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.res.Configuration;
import android.view.WindowManager;

public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      Configuration config = getResources().getConfiguration();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
/**
* Landscape mode of the device
*/
LM_Fragment ls_fragment = new LM_Fragment();
fragmentTransaction.replace(android.R.id.content, ls_fragment);
}else{
/**
* Portrait mode of the device
*/
PM_Fragment pm_fragment = new PM_Fragment();
fragmentTransaction.replace(android.R.id.content, pm_fragment);
}
fragmentTransaction.commit();
}

}
Anjali
  • 598
  • 2
  • 5
  • 15
  • possible duplicate of [android.support.v4.app.FragmentManager OR android.app.FragmentManager?](http://stackoverflow.com/questions/23044826/android-support-v4-app-fragmentmanager-or-android-app-fragmentmanager) – M D Dec 01 '14 at 10:42

3 Answers3

1

your activity should extend FragmentActivity. support libraries introduced to add some functionalities to older Androids. For example Fragments were introduced in Android 3.0 (SDK nr: 11). In fact (according to documentation) in Androids 3.0 < support libary uses system implementation of Fragments.

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19
  • Copy & Paste [http://stackoverflow.com/questions/23044826/android-support-v4-app-fragmentmanager-or-android-app-fragmentmanager](http://stackoverflow.com/questions/23044826/android-support-v4-app-fragmentmanager-or-android-app-fragmentmanager) – M D Dec 01 '14 at 10:48
  • Still it shows error. "The import android.app.FragmentManager cannot be resolved." "The import android.app.FragmentTransaction cannot be resolved." – Anjali Dec 01 '14 at 11:28
0

Your activity should extends FragmentActivity so you can use getSupportFragmentManager() (on older device) if you are targeting only newer device use (extend Activity): getFragmentManager()

Unii
  • 1,587
  • 15
  • 33
0

Have a look at your imports they are-:

import android.support.v4.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

if you are importing v4 fragment as you did use getsupportfragmentmanager()

then other imports will be...

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

to use getFragmentManager() your imports should be

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

mark as up if this helps

Harry Sharma
  • 2,190
  • 2
  • 15
  • 41