IllegalArgumentException: savedInstanceState Specified as Non-Null is Null











up vote
16
down vote

favorite












I am getting a strange error when I start my MainActivity:



06-16 16:01:05.193 2083-2083/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.github, PID: 2083
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.github/com.android.example.github.ui.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt)
at android.app.Application.dispatchActivityCreated(Application.java:197)
at android.app.Activity.onCreate(Activity.java:961)
at android.support.v4.app.BaseFragmentActivityGingerbread.onCreate(BaseFragmentActivityGingerbread.java:54)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:319)
at com.android.example.github.ui.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6121) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 


This is my MainActivity class:



class MainActivity : LifecycleActivity(), HasSupportFragmentInjector {

lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject set

lateinit var navigationController: NavigationController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

if (savedInstanceState == null) {
navigationController.navigateToSearch()
}
}

override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return dispatchingAndroidInjector
}

}


The error states that the parameter savedInstanceState is null, when it is specified as non-null; but it is nullable (savedInstanceState: Bundle?) and the onCreate() method is marked as @Nullable in the source.



I have not come across this error in any of my other Kotlin projects. I am using Kotlin version 1.1.2-5; and had the same error with 1.1.2-3.










share|improve this question






















  • I have same issue. what is the issue on AppInjector, can you suggest it
    – Ramki Anba
    Dec 27 '17 at 6:39















up vote
16
down vote

favorite












I am getting a strange error when I start my MainActivity:



06-16 16:01:05.193 2083-2083/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.github, PID: 2083
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.github/com.android.example.github.ui.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt)
at android.app.Application.dispatchActivityCreated(Application.java:197)
at android.app.Activity.onCreate(Activity.java:961)
at android.support.v4.app.BaseFragmentActivityGingerbread.onCreate(BaseFragmentActivityGingerbread.java:54)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:319)
at com.android.example.github.ui.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6121) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 


This is my MainActivity class:



class MainActivity : LifecycleActivity(), HasSupportFragmentInjector {

lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject set

lateinit var navigationController: NavigationController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

if (savedInstanceState == null) {
navigationController.navigateToSearch()
}
}

override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return dispatchingAndroidInjector
}

}


The error states that the parameter savedInstanceState is null, when it is specified as non-null; but it is nullable (savedInstanceState: Bundle?) and the onCreate() method is marked as @Nullable in the source.



I have not come across this error in any of my other Kotlin projects. I am using Kotlin version 1.1.2-5; and had the same error with 1.1.2-3.










share|improve this question






















  • I have same issue. what is the issue on AppInjector, can you suggest it
    – Ramki Anba
    Dec 27 '17 at 6:39













up vote
16
down vote

favorite









up vote
16
down vote

favorite











I am getting a strange error when I start my MainActivity:



06-16 16:01:05.193 2083-2083/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.github, PID: 2083
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.github/com.android.example.github.ui.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt)
at android.app.Application.dispatchActivityCreated(Application.java:197)
at android.app.Activity.onCreate(Activity.java:961)
at android.support.v4.app.BaseFragmentActivityGingerbread.onCreate(BaseFragmentActivityGingerbread.java:54)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:319)
at com.android.example.github.ui.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6121) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 


This is my MainActivity class:



class MainActivity : LifecycleActivity(), HasSupportFragmentInjector {

lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject set

lateinit var navigationController: NavigationController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

if (savedInstanceState == null) {
navigationController.navigateToSearch()
}
}

override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return dispatchingAndroidInjector
}

}


The error states that the parameter savedInstanceState is null, when it is specified as non-null; but it is nullable (savedInstanceState: Bundle?) and the onCreate() method is marked as @Nullable in the source.



I have not come across this error in any of my other Kotlin projects. I am using Kotlin version 1.1.2-5; and had the same error with 1.1.2-3.










share|improve this question













I am getting a strange error when I start my MainActivity:



06-16 16:01:05.193 2083-2083/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.github, PID: 2083
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.github/com.android.example.github.ui.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt)
at android.app.Application.dispatchActivityCreated(Application.java:197)
at android.app.Activity.onCreate(Activity.java:961)
at android.support.v4.app.BaseFragmentActivityGingerbread.onCreate(BaseFragmentActivityGingerbread.java:54)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:319)
at com.android.example.github.ui.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6121) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 


This is my MainActivity class:



class MainActivity : LifecycleActivity(), HasSupportFragmentInjector {

lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject set

lateinit var navigationController: NavigationController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

if (savedInstanceState == null) {
navigationController.navigateToSearch()
}
}

override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return dispatchingAndroidInjector
}

}


The error states that the parameter savedInstanceState is null, when it is specified as non-null; but it is nullable (savedInstanceState: Bundle?) and the onCreate() method is marked as @Nullable in the source.



I have not come across this error in any of my other Kotlin projects. I am using Kotlin version 1.1.2-5; and had the same error with 1.1.2-3.







android android-activity kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 16 '17 at 20:18









Bryan

7,40833784




7,40833784












  • I have same issue. what is the issue on AppInjector, can you suggest it
    – Ramki Anba
    Dec 27 '17 at 6:39


















  • I have same issue. what is the issue on AppInjector, can you suggest it
    – Ramki Anba
    Dec 27 '17 at 6:39
















I have same issue. what is the issue on AppInjector, can you suggest it
– Ramki Anba
Dec 27 '17 at 6:39




I have same issue. what is the issue on AppInjector, can you suggest it
– Ramki Anba
Dec 27 '17 at 6:39












4 Answers
4






active

oldest

votes

















up vote
6
down vote



accepted










It seems like the issue isn't in the onCreate method. Try looking at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt). I can't tell if it's a generated class, but it should give you an idea of what to do next.






share|improve this answer




























    up vote
    34
    down vote













    I had the exact same problem, you have to make nullable types here:



    override fun onCreatePreferences(bundle: Bundle?, s: String?) {}





    share|improve this answer





















    • What if i can't able to change this definition? for ex. SDK library functions!
      – Kishore Jethava
      Dec 31 '17 at 12:48






    • 2




      Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
      – Lucas P.
      Mar 8 at 22:59










    • Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
      – Michael Osofsky
      May 21 at 17:49


















    up vote
    5
    down vote













    The issue is in the AppInjector. I used the google GitHubBrowser sample like you did and ran into this same error. I copied the code over to my project and let Android Studio convert it to Kotlin. When it did this it didn't properly specify the nullability of the savedInstanceState parameter which is what is causing the crash. Just make it optional like in the below code and it will work.



    object AppInjector {
    fun init(app: App) {
    DaggerAppComponent.builder().application(app)
    .build().inject(app)
    app
    .registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
    handleActivity(activity)
    }

    override fun onActivityStarted(activity: Activity) {

    }

    override fun onActivityResumed(activity: Activity) {

    }

    override fun onActivityPaused(activity: Activity) {

    }

    override fun onActivityStopped(activity: Activity) {

    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

    }

    override fun onActivityDestroyed(activity: Activity) {

    }
    })
    }

    private fun handleActivity(activity: Activity) {
    if (activity is HasSupportFragmentInjector) {
    AndroidInjection.inject(activity)
    }
    (activity as? FragmentActivity)?.supportFragmentManager?.registerFragmentLifecycleCallbacks(
    object : FragmentManager.FragmentLifecycleCallbacks() {
    override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?,
    savedInstanceState: Bundle?) {
    if (f is Injectable) {
    AndroidSupportInjection.inject(f)
    }
    }
    }, true)
    }
    }





    share|improve this answer





















    • my hero !. saved me hours of time. thanks
      – j2emanue
      Feb 10 at 13:13


















    up vote
    1
    down vote













    As @mcassiano noted, it appears the issue isn't with your onCreate method but actually onActivityCreated. Two thoughts:




    • Due to the fact that libraries and such are in transition, for now you may have to just manually override onActivityCreated in your fragment and explicitly mark the Bundle as nullable: (savedInstanceState: Bundle?). You shouldn't have to, but manually setting up the nullability may just help.

    • I notice that the crash goes all the way down to BaseFragmentActivityGingerbread - is this a result of using the LifecycleActivity? Or do you have other, older, out-of-date dependencies in your project?






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44597348%2fillegalargumentexception-savedinstancestate-specified-as-non-null-is-null%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      6
      down vote



      accepted










      It seems like the issue isn't in the onCreate method. Try looking at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt). I can't tell if it's a generated class, but it should give you an idea of what to do next.






      share|improve this answer

























        up vote
        6
        down vote



        accepted










        It seems like the issue isn't in the onCreate method. Try looking at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt). I can't tell if it's a generated class, but it should give you an idea of what to do next.






        share|improve this answer























          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          It seems like the issue isn't in the onCreate method. Try looking at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt). I can't tell if it's a generated class, but it should give you an idea of what to do next.






          share|improve this answer












          It seems like the issue isn't in the onCreate method. Try looking at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt). I can't tell if it's a generated class, but it should give you an idea of what to do next.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 16 '17 at 20:27









          mcassiano

          1856




          1856
























              up vote
              34
              down vote













              I had the exact same problem, you have to make nullable types here:



              override fun onCreatePreferences(bundle: Bundle?, s: String?) {}





              share|improve this answer





















              • What if i can't able to change this definition? for ex. SDK library functions!
                – Kishore Jethava
                Dec 31 '17 at 12:48






              • 2




                Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
                – Lucas P.
                Mar 8 at 22:59










              • Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
                – Michael Osofsky
                May 21 at 17:49















              up vote
              34
              down vote













              I had the exact same problem, you have to make nullable types here:



              override fun onCreatePreferences(bundle: Bundle?, s: String?) {}





              share|improve this answer





















              • What if i can't able to change this definition? for ex. SDK library functions!
                – Kishore Jethava
                Dec 31 '17 at 12:48






              • 2




                Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
                – Lucas P.
                Mar 8 at 22:59










              • Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
                – Michael Osofsky
                May 21 at 17:49













              up vote
              34
              down vote










              up vote
              34
              down vote









              I had the exact same problem, you have to make nullable types here:



              override fun onCreatePreferences(bundle: Bundle?, s: String?) {}





              share|improve this answer












              I had the exact same problem, you have to make nullable types here:



              override fun onCreatePreferences(bundle: Bundle?, s: String?) {}






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 26 '17 at 22:02









              lxknvlk

              1,2611120




              1,2611120












              • What if i can't able to change this definition? for ex. SDK library functions!
                – Kishore Jethava
                Dec 31 '17 at 12:48






              • 2




                Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
                – Lucas P.
                Mar 8 at 22:59










              • Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
                – Michael Osofsky
                May 21 at 17:49


















              • What if i can't able to change this definition? for ex. SDK library functions!
                – Kishore Jethava
                Dec 31 '17 at 12:48






              • 2




                Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
                – Lucas P.
                Mar 8 at 22:59










              • Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
                – Michael Osofsky
                May 21 at 17:49
















              What if i can't able to change this definition? for ex. SDK library functions!
              – Kishore Jethava
              Dec 31 '17 at 12:48




              What if i can't able to change this definition? for ex. SDK library functions!
              – Kishore Jethava
              Dec 31 '17 at 12:48




              2




              2




              Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
              – Lucas P.
              Mar 8 at 22:59




              Thanks! My DialogFragments (converted form java to Kotlin from Android Studio) were crashing and just a simple ? on the Bundle in the onCreateDialog(savedInstanceState: Bundle?): Dialog fixed it!
              – Lucas P.
              Mar 8 at 22:59












              Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
              – Michael Osofsky
              May 21 at 17:49




              Seems like this changes the signature of an inherited function. I confirmed it works though, no compiler errors. In what other ways can we change the signature of a function that we override?
              – Michael Osofsky
              May 21 at 17:49










              up vote
              5
              down vote













              The issue is in the AppInjector. I used the google GitHubBrowser sample like you did and ran into this same error. I copied the code over to my project and let Android Studio convert it to Kotlin. When it did this it didn't properly specify the nullability of the savedInstanceState parameter which is what is causing the crash. Just make it optional like in the below code and it will work.



              object AppInjector {
              fun init(app: App) {
              DaggerAppComponent.builder().application(app)
              .build().inject(app)
              app
              .registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
              override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
              handleActivity(activity)
              }

              override fun onActivityStarted(activity: Activity) {

              }

              override fun onActivityResumed(activity: Activity) {

              }

              override fun onActivityPaused(activity: Activity) {

              }

              override fun onActivityStopped(activity: Activity) {

              }

              override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

              }

              override fun onActivityDestroyed(activity: Activity) {

              }
              })
              }

              private fun handleActivity(activity: Activity) {
              if (activity is HasSupportFragmentInjector) {
              AndroidInjection.inject(activity)
              }
              (activity as? FragmentActivity)?.supportFragmentManager?.registerFragmentLifecycleCallbacks(
              object : FragmentManager.FragmentLifecycleCallbacks() {
              override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?,
              savedInstanceState: Bundle?) {
              if (f is Injectable) {
              AndroidSupportInjection.inject(f)
              }
              }
              }, true)
              }
              }





              share|improve this answer





















              • my hero !. saved me hours of time. thanks
                – j2emanue
                Feb 10 at 13:13















              up vote
              5
              down vote













              The issue is in the AppInjector. I used the google GitHubBrowser sample like you did and ran into this same error. I copied the code over to my project and let Android Studio convert it to Kotlin. When it did this it didn't properly specify the nullability of the savedInstanceState parameter which is what is causing the crash. Just make it optional like in the below code and it will work.



              object AppInjector {
              fun init(app: App) {
              DaggerAppComponent.builder().application(app)
              .build().inject(app)
              app
              .registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
              override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
              handleActivity(activity)
              }

              override fun onActivityStarted(activity: Activity) {

              }

              override fun onActivityResumed(activity: Activity) {

              }

              override fun onActivityPaused(activity: Activity) {

              }

              override fun onActivityStopped(activity: Activity) {

              }

              override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

              }

              override fun onActivityDestroyed(activity: Activity) {

              }
              })
              }

              private fun handleActivity(activity: Activity) {
              if (activity is HasSupportFragmentInjector) {
              AndroidInjection.inject(activity)
              }
              (activity as? FragmentActivity)?.supportFragmentManager?.registerFragmentLifecycleCallbacks(
              object : FragmentManager.FragmentLifecycleCallbacks() {
              override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?,
              savedInstanceState: Bundle?) {
              if (f is Injectable) {
              AndroidSupportInjection.inject(f)
              }
              }
              }, true)
              }
              }





              share|improve this answer





















              • my hero !. saved me hours of time. thanks
                – j2emanue
                Feb 10 at 13:13













              up vote
              5
              down vote










              up vote
              5
              down vote









              The issue is in the AppInjector. I used the google GitHubBrowser sample like you did and ran into this same error. I copied the code over to my project and let Android Studio convert it to Kotlin. When it did this it didn't properly specify the nullability of the savedInstanceState parameter which is what is causing the crash. Just make it optional like in the below code and it will work.



              object AppInjector {
              fun init(app: App) {
              DaggerAppComponent.builder().application(app)
              .build().inject(app)
              app
              .registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
              override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
              handleActivity(activity)
              }

              override fun onActivityStarted(activity: Activity) {

              }

              override fun onActivityResumed(activity: Activity) {

              }

              override fun onActivityPaused(activity: Activity) {

              }

              override fun onActivityStopped(activity: Activity) {

              }

              override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

              }

              override fun onActivityDestroyed(activity: Activity) {

              }
              })
              }

              private fun handleActivity(activity: Activity) {
              if (activity is HasSupportFragmentInjector) {
              AndroidInjection.inject(activity)
              }
              (activity as? FragmentActivity)?.supportFragmentManager?.registerFragmentLifecycleCallbacks(
              object : FragmentManager.FragmentLifecycleCallbacks() {
              override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?,
              savedInstanceState: Bundle?) {
              if (f is Injectable) {
              AndroidSupportInjection.inject(f)
              }
              }
              }, true)
              }
              }





              share|improve this answer












              The issue is in the AppInjector. I used the google GitHubBrowser sample like you did and ran into this same error. I copied the code over to my project and let Android Studio convert it to Kotlin. When it did this it didn't properly specify the nullability of the savedInstanceState parameter which is what is causing the crash. Just make it optional like in the below code and it will work.



              object AppInjector {
              fun init(app: App) {
              DaggerAppComponent.builder().application(app)
              .build().inject(app)
              app
              .registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
              override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
              handleActivity(activity)
              }

              override fun onActivityStarted(activity: Activity) {

              }

              override fun onActivityResumed(activity: Activity) {

              }

              override fun onActivityPaused(activity: Activity) {

              }

              override fun onActivityStopped(activity: Activity) {

              }

              override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

              }

              override fun onActivityDestroyed(activity: Activity) {

              }
              })
              }

              private fun handleActivity(activity: Activity) {
              if (activity is HasSupportFragmentInjector) {
              AndroidInjection.inject(activity)
              }
              (activity as? FragmentActivity)?.supportFragmentManager?.registerFragmentLifecycleCallbacks(
              object : FragmentManager.FragmentLifecycleCallbacks() {
              override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?,
              savedInstanceState: Bundle?) {
              if (f is Injectable) {
              AndroidSupportInjection.inject(f)
              }
              }
              }, true)
              }
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 13 at 20:04









              Chris

              1,37011221




              1,37011221












              • my hero !. saved me hours of time. thanks
                – j2emanue
                Feb 10 at 13:13


















              • my hero !. saved me hours of time. thanks
                – j2emanue
                Feb 10 at 13:13
















              my hero !. saved me hours of time. thanks
              – j2emanue
              Feb 10 at 13:13




              my hero !. saved me hours of time. thanks
              – j2emanue
              Feb 10 at 13:13










              up vote
              1
              down vote













              As @mcassiano noted, it appears the issue isn't with your onCreate method but actually onActivityCreated. Two thoughts:




              • Due to the fact that libraries and such are in transition, for now you may have to just manually override onActivityCreated in your fragment and explicitly mark the Bundle as nullable: (savedInstanceState: Bundle?). You shouldn't have to, but manually setting up the nullability may just help.

              • I notice that the crash goes all the way down to BaseFragmentActivityGingerbread - is this a result of using the LifecycleActivity? Or do you have other, older, out-of-date dependencies in your project?






              share|improve this answer

























                up vote
                1
                down vote













                As @mcassiano noted, it appears the issue isn't with your onCreate method but actually onActivityCreated. Two thoughts:




                • Due to the fact that libraries and such are in transition, for now you may have to just manually override onActivityCreated in your fragment and explicitly mark the Bundle as nullable: (savedInstanceState: Bundle?). You shouldn't have to, but manually setting up the nullability may just help.

                • I notice that the crash goes all the way down to BaseFragmentActivityGingerbread - is this a result of using the LifecycleActivity? Or do you have other, older, out-of-date dependencies in your project?






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  As @mcassiano noted, it appears the issue isn't with your onCreate method but actually onActivityCreated. Two thoughts:




                  • Due to the fact that libraries and such are in transition, for now you may have to just manually override onActivityCreated in your fragment and explicitly mark the Bundle as nullable: (savedInstanceState: Bundle?). You shouldn't have to, but manually setting up the nullability may just help.

                  • I notice that the crash goes all the way down to BaseFragmentActivityGingerbread - is this a result of using the LifecycleActivity? Or do you have other, older, out-of-date dependencies in your project?






                  share|improve this answer












                  As @mcassiano noted, it appears the issue isn't with your onCreate method but actually onActivityCreated. Two thoughts:




                  • Due to the fact that libraries and such are in transition, for now you may have to just manually override onActivityCreated in your fragment and explicitly mark the Bundle as nullable: (savedInstanceState: Bundle?). You shouldn't have to, but manually setting up the nullability may just help.

                  • I notice that the crash goes all the way down to BaseFragmentActivityGingerbread - is this a result of using the LifecycleActivity? Or do you have other, older, out-of-date dependencies in your project?







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 16 '17 at 22:14









                  creativedrewy

                  794




                  794






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44597348%2fillegalargumentexception-savedinstancestate-specified-as-non-null-is-null%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Lugert, Oklahoma