14

Unused import declaration "import android .support.v7.app.AppCompatActivity

 3 years ago
source link: https://www.codesd.com/item/unused-import-declaration-import-android-support-v7-app-appcompatactivity.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Unused import declaration "import android .support.v7.app.AppCompatActivity

advertisements

I have a sliding menu that uses fragments, each fragment activity are extending Fragment. One of the activities, Slider_Fragment2.java needs to import the android.support.v7.app.AppCompatActivity. The problem is, it kept on appearing as unused.

Here's my dependencies:

compile 'com.android.support:support-v4:23.0.3'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:design:23.1.0'

Here's what I've tried so far:

*I removed the appcompat library in the module settings and added it again, they're the same version of my support library.

*Clean and build the project

*Checked the libs folder of my project and looked for android-support-v4.jar for deletion, but I have none.

*Changed the declaration of my class to Slider_Fragment2 extends AppCompatActivty, this removed the errors in the activity but another appeared in my MainActivity where I have a function, replaceFragment() requiring the activities to extend Fragment only.

Here's my replaceFragment():

private void replaceFragment(int pos){
    Fragment fragment = null;
    switch(pos){
        case 0:
            fragment = new Slider_Fragment1();
            break;
        case 1:
            fragment = new Slider_Fragment2();
            break;
        case 2:
            fragment = new Slider_Fragment3();
            break;
        case 3:
            fragment = new Slider_Fragment4();
            break;
        case 4:
            fragment = new Slider_Fragment5();
            break;
        case 5:
            fragment = new Slider_Fragment6();
            break;
        case 6:
            fragment = new Slider_Fragment7();
            break;
        default:
            fragment = new Slider_Fragment1();
            break;
    }

    if(null!=fragment){
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.main_content, fragment);
        transaction.addToBackStack(null);
        transaction.commit();
    }

}


Remove the stated import statements first. If it is really required, the Classes that need it will get highlighted. Take your cursor to the erroring Class references and press Alt+Enter and then select import.... It will get the right packages and add imports.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK