kotlin 'onCreate' overrides nothing
36,383
Solution 1
It seems some functions have changed in the last update,
just remove the '?
' from the Bundle
Like this:
override fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
}
Solution 2
It can happen also in a Fragment class: I found the same issue for the method onCreateView
; to avoid that, just remove the ?
from the LayoutInflater
parameter,
Like this:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
Solution 3
I have to add "?" when using appcompat-v7:27.1.1
implementation "com.android.support:appcompat-v7:27.1.1
and
override fun onCreate(savedInstanceState : Bundle?){
super.onCreate(savedInstanceState)
}
Author by
RootKit
Updated on July 09, 2022Comments
-
RootKit almost 2 years
I am using component development, in my common module BaseActivity.kt and BaseFragment.kt. The following problems occur when other modules inherit them
> D:\Android\OneDaily\module_main\src\main\java\com\boco\main\MainActivity.kt > Error:(7, 24) Unresolved reference: base > Error:(9, 22) Unresolved reference: BaseActivity > Error:(21, 5) 'onCreate' overrides nothing > Error:(17, 5) 'getLayoutRes' overrides nothing > Error:(22, 15) Unresolved reference: onCreate > Error:(27, 22) Unresolved reference: findViewById > Error:(42, 34) Unresolved reference: supportFragmentManager > D:\Android\OneDaily\module_main\src\main\java\com\boco\main\TimelineFragment.kt > Error:(7, 24) Unresolved reference: base > Error:(10, 5) 'getLayoutRes' overrides nothing > Error:(9, 26) Unresolved reference: BaseFragment > Error:(14, 5) 'onCreateView' overrides nothing > Error:(15, 22) Unresolved reference: onCreateView
BaseActivity.kt:
abstract class BaseActivity : AppCompatActivity() { init { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) } abstract fun getLayoutRes(): Int override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(getLayoutRes()) } }
MainActivity.kt
class MainActivity : BaseActivity() { private lateinit var mBottomNav: BottomNavigationView private var mFragment1 = TimelineFragment() as Fragment private var mFragment2 = TimelineFragment() as Fragment private var mFragment3 = TimelineFragment() as Fragment override fun getLayoutRes(): Int { return R.layout.activity_main } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } }
-
alex over 6 yearsWould help to see your code.
-
Kiran Benny Joseph over 6 yearsplease share your code snippet
-
Haresh Chhelana over 6 yearsI have try your given code with Android Studio 3.0 stable version and it's working fine. have you using same or other version of android studio ?
-
RootKit over 6 yearsI am also using Android studio 3.0 But my MainActivity.kt is a baseActivity.kt that inherits from module. BaseActivity.kt inside the common module, MainActivity.kt inside module_main.I do not know if you are trying to do so
-
saiedmomen over 6 yearsI'm seeing the same error after moving to support library version 27.0.0
-
tynn over 6 years
Unresolved reference: BaseActivity
– this might be related to a configuration issue with Gradle... -
RootKit over 6 yearsoh, thank you, really is the problem of Gradle. My common module did not apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions'
-
Aba over 6 yearsMaybe this might help: stackoverflow.com/questions/47016853/…
-
-
RootKit over 6 yearsWhich version can remove '?'
-
Emmanuel Guther over 6 yearsAlso, if you are getting same error but in a fragment, remove '?' in fragmentManager: FragmentManager
-
romaneso over 6 yearsThis answer should be selected as the top-answer. Helped me out!
-
jbass about 6 yearsWorked for me for 27.0.2 as well.
-
onmyway133 almost 6 yearsYeah, otherwise you will get "Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState"
-
zeeshan over 5 yearsWorked for me on Android Studio 3.3, appcompat-v7:28.0.0, compileSdkVersion 28
-
Hannah S. almost 5 yearsI'm using Android 3.5 and had the same problem the OP had but for onCreateDialog() not onCreate(). I was using the example from developer.android.com/guide/topics/ui/dialogs.html#kotlin which had no ? after Bundle, but adding it fixed it. Thanks so much for the suggestion!
-
mr5 almost 4 yearsHad this problem but the solution was to add
?
inBundle
. I'm using AS: 4.0, Kotlin: 1.3.72, Gradle: 4.9 -
dicarlomagnus over 3 yearsthis works as well for override fun onDismiss(dialog: DialogInterface?) removing the nullable parameter to override fun onDismiss(dialog: DialogInterface)
-
Taslim Oseni over 2 yearsWorked like a charm!