Here is the code I have. I'm getting a red line under new MainFragment();
with the error Type mismatch: cannot convert from WishlistFragment to Fragment
:
Fragment newfragment = new MainFragment();
Here is what my MainFragment.java file looks like:
public class MainFragment extends Fragment {
public MainFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
Any ides on why this is happening? I have a feeling it's something stupid I am looking over and I am just code-blind right now from a long day.
Make sure that both places are importing the same Fragment
class. It feels a bit like in one place you are importing android.app.Fragment
(the native API Level 11 version of fragments) and in the other places you are importing android.support.v4.app.Fragment
(the fragments from the Android Support package).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With