Kotlin:找不到符号类Fragment或其他android类

时间:2021-05-28 15:19:49

I have a java fragment with viewPager in it..

我有一个带有viewPager的java片段。

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 :

现在我有另一个片段将填充在上面的片段中,并用kotlin写成:

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

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

我没有得到任何lint警告或错误但是当我尝试运行应用程序时:

But I get a error :

但我收到一个错误:

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

错误:(79,37)错误:找不到符号类DeshFalView

in the highlighted line above .. those two classes are inside same package as shown below Kotlin:找不到符号类Fragment或其他android类

在上面突出显示的行中..这两个类在同一个包中,如下所示

Thanks in advance ...

提前致谢 ...

1 个解决方案

#1


28  

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

问题:我犯了一个愚蠢的错误,我忘了应用kotlin-android插件

Solution : On the top of app gradle file paste :

解决方案:在应用程序gradle文件粘贴的顶部:

apply plugin: 'kotlin-android'

#1


28  

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

问题:我犯了一个愚蠢的错误,我忘了应用kotlin-android插件

Solution : On the top of app gradle file paste :

解决方案:在应用程序gradle文件粘贴的顶部:

apply plugin: 'kotlin-android'