Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin : Cannot find symbol class Fragment or other android classes

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 ...

like image 365
erluxman Avatar asked May 29 '17 17:05

erluxman


People also ask

How do I get rid of Cannot find symbol error?

In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.

What is the error Cannot find symbol?

The “cannot find symbol” error comes up mainly when we try to use a variable that's not defined or declared in our program. When our code compiles, the compiler needs to verify all the identifiers we have. The error “cannot find symbol” means we're referring to something that the compiler doesn't know about.

What is Br in data binding Android?

} Note: The Data Binding Library generates a class named BR in the module package which contains the IDs of the resources used for data binding. In the example above, the library automatically generates the BR. item variable.


2 Answers

Sometimes I had this kind of error even when this:

apply plugin: 'kotlin-android'

was in my app gradle.

The solution is to delete the app/build directory. This folder is auto generated so there will be no problems deleting it.

Hope this will help somebody.

like image 86
acmpo6ou Avatar answered Oct 19 '22 07:10

acmpo6ou


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'
like image 43
erluxman Avatar answered Oct 19 '22 07:10

erluxman