When I try to click on the item that should transfer me to the fragment, I get an error + the application crashes:

02-27 12: 01: 14.470 21264-21264 / com.sai.android E / ACRA: ACRA caught a IllegalArgumentException for com ... android java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm .internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState at com.sai.android.views.LanguageSelectorFragment.onCreateView (LanguageSelectorFragment.kt) at android.app.Fragment.performCreateView (Fragment.java2069) at isaarea, this is our template, this is for you by template.app. FragmentManager.java:899) at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1072) at android.app.BackStackRecord.run (BackStackRecord.java:852) at android.app.FragmentManagerImplcphrccecord.java:852) at android.app.FragmentManagerImplccaccecord.java:852) at android.app.FragmentManagerImplccaccecord.j.:unun.phloe, etc, etc ) at android.app.FragmentManagerImpl $ 1.run (FragmentManager.java:452) at android.os.Handler.handleCallback (Handler.java:815) at android.os.Handler.dispatchMessage (Handler.java:104) at android. os.Looper.loop (Looper.java:194) at android.app.ActivityThread.main (ActivityThread.java: 5637) at java.lang.reflect.Method.invoke (Native Method) at java.lang.reflect.Method.invoke (Method.java.0672) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit. java: 959) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)

So I understand the problems with back stack. But in what exactly, I find it difficult to localize the problem.

  • 2
    Well, in general, it seems to be written here that the null safety stated in Kotlin actually found that for savedInstanceState is null when it should not be. - pavlofff
  • @pavlofff why is that? when do i have false for this parameter? in onCreateView method - Inkognito
  • I do not know, because of the non-disconnecting null safety, I do not use Kotlin, although otherwise I like it. - pavlofff
  • @pavlofff, declare types as nullable and will be like in Java :) - Eugene Krivenja

2 answers 2

Well, first, as I understand you are writing to kotlin, as the logs clearly indicate this.

Well, and secondly, when you declare the parameter savedInstanceState you need to explicitly specify the type - Bundle? , this is something like bugs in Kotlin'e. Also, if you use it in the onCreate method, then it would be better to do this as follows (in the example I use the elvis operator), namely assign an empty Bundle:

  override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState ?: Bundle()) 
  • No dancing with the savedInstanceState ?: Bundle() is needed, just passed to super.onCreate(savedInstanceState) . And this is not a bug, you just need to understand when it is nullable , and when it is non-nullable . - Eugene Krivenja

You have an error in declaring the LanguageSelectorFragment.onCreateView() method, judging by the official documentation , two of the three parameters can be null , so on Kotlin it should look like this:

 fun onCreateView (inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?