Home » Android » java – Kotlin : Cannot find symbol class Fragment or other android classes

java – Kotlin : Cannot find symbol class Fragment or other android classes

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a java fragment with viewPager in it..

public class FragmentWithViewPager extends Fragment {

    private class ViewPagerAdapter extends FragmentStatePagerAdapter {

        ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            Fragment fragment = new DeshFalView(); //<-- Problem here
            Bundle args = new Bundle();
            args.putInt("index", i);
            fragment.setArguments(args);
            return fragment;
        }

    }
}

Now I have another fragment which will be populated inside the above fragment and is written in kotlin like this :

class DeshFalView : Fragment(), DeshfalContract.View {
    //More code...
}

I do not get any lint warning or error but when I try to run the app:

But I get a error :

Error:(79, 37) error: cannot find symbol class DeshFalView

in the highlighted line above ..
those two classes are inside same package as shown below enter image description here

Thanks in advance …

How to&Answers:

Problem : I made a stupid mistake that I forgot to apply kotlin-android plugin

Solution : On the top of app gradle file paste :

apply plugin: 'kotlin-android'