Java – Activity is not assigned to Android.app.Activity Manifest XML

Activity is not assigned to Android.app.Activity Manifest XML… here is a solution to the problem.

Activity is not assigned to Android.app.Activity Manifest XML

I’m having some issues with fragments in Android Studio. So basically this is my MainActivity:

public class MainActivity extends FragmentActivity {
final Context context = this;

ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
    Tab = (ViewPager) findViewById(R.id.pager);
    Tab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar = getActionBar();
            actionBar.setSelectedNavigationItem(position);
        }
    });
    Tab.setAdapter(TabAdapter);
    actionBar = getActionBar();
     Enable Tabs on Action Bar
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabReselected(android.app.ActionBar.Tab tab,
                                    android.app.FragmentTransaction ft) {
        }

@Override
        public void onTabSelected(android.app.ActionBar.Tab tab,
                                  android.app.FragmentTransaction ft) {
             on tab selected show respected fragment view
            Tab.setCurrentItem(tab.getPosition());
        }

@Override
        public void onTabUnselected(android.app.ActionBar.Tab tab,
                                    android.app.FragmentTransaction ft) {
        }
    };

 Add New Tab
    actionBar.addTab(actionBar.newTab().setText("Feedback")
            .setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("History Log")
            .setTabListener(tabListener));

}
}

Then my other class is one of the tag codes :

public class FeedbackMain extends Fragment {
View feedbackMainView;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

feedbackMainView = inflater.inflate(R.layout.activity_feedback_main,
            container, false);

return feedbackMainView;
}
}

Then my list :

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=". MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=". FeedbackMain"
        android:label="@string/title_activity_feedback_main" >
    </activity>

However, I am in the . FeedbackMain receives a red line and the error message is:

. FeedbackMain is not assignable to 'android.app.Activity'

I wonder why this is the case? It works fine on Android dev tools, but that’s what happened when I switched to Android Studio.

Thanks in advance.

Edit

XML file for mainActivity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Style .xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

</resources>

Solution

First, you simply declare the activity in the list file, not the fragment.
So remove this line from the list file

<activity
        android:name=". FeedbackMain"
        android:label="@string/title_activity_feedback_main" >
    </activity>

Second, if you want to use ActionBar, your class should extend ActionBarActivity instead of FragmentActivity. So change your mainactivity from

public class MainActivity extends FragmentActivity {

to

public class MainActivity extends ActionBarActivity{

Then make sure to call getSupportActionBar() if you are using the support library

Edit:

ActionBar.TabListener tabListener = new ActionBar.TabListener() { 
@Override 
public void onTabReselected( 
android.support.v7.app.ActionBar.Tab arg0, 
FragmentTransaction arg1) { 
 TODO Auto-generated method stub 

} 

@Override 
public void onTabSelected( 
android.support.v7.app.ActionBar.Tab arg0, 
FragmentTransaction arg1) { 
 TODO Auto-generated method stub 

} 

@Override 
public void onTabUnselected( 
android.support.v7.app.ActionBar.Tab arg0, 
FragmentTransaction arg1) { 
 TODO Auto-generated method stub 

} 
};

Related Problems and Solutions