Multiple Errors In My Fragments After Updating The Support Library To 27.0.0
Solution 1:
The Root cause of all of these errors is that in support library v-27.0.0 @Nullable and @NonNullannotations have been added.
and since kotlin language is aware of nullability and has a different type for Nullable and NonNull, unlike Java.
without these annotations, the compiler has no way of differentiating between them, and Android studio was trying his best to infer the right type.
TL;DR: change the types to rightly reflect the nullability status.
Error: Smart cast to 'Bundle' is impossible, because 'arguments' is a mutable property that could have been changed by this time.
change arguments.getString(ARG_NAME) ==> arguments?.getString(ARG_NAME) ?: ""
Error: 'onCreateView' overrides nothing
chane:
overridefunonCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View?
==>
overridefunonCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
Error: 'onViewCreated' overrides nothing
change:
overridefunonViewCreated(view: View?, savedInstanceState: Bundle?)==>
overridefunonViewCreated(view: View, savedInstanceState: Bundle?)Error: Type mismatch: inferred type is Context? but Context was expected
if context is passed as argument to method, just use the quick fix to replace getContext() with getContext()?.let{}
the same applies to the kotlin short version context.
else if is used to call some method replace getContext().someMethod() with getContext()?.someMethod()
the same applies to the kotlin short version context?.someMethod().
Error: Type mismatch: inferred type is FragmentActivity? but Context was expected
use the fix of the previous error.
Solution 2:
For error message:
Type mismatch: inferred type is Bundle? but Bundle was expected
In class: Fragment, method: onCreateView
From
val arguments = SleepQualityFragmentArgs.fromBundle(arguments)
To
valarguments= SleepQualityFragmentArgs.fromBundle(requireArguments())
Post a Comment for "Multiple Errors In My Fragments After Updating The Support Library To 27.0.0"