title: Kotlin Constructor Crash
body: <p>In every single tutorial about inheritance for kotlin I've seen an example like this:</p>
  
  <pre><code>class SubClass(pref : String)  {
      fun theSubClassMethod() : String {
          return "The subclass method"
      }
  }
  </code></pre>
  
  <p>However, if I use it as such, for some reason I get this exception:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
                                                         at a.b.c.com.logic.SubClass.&lt;init&gt;(SubClass.kt)
                                                         at a.b.c.com.kotlinplayground.MainActivity.onCreate(MainActivity.kt:39)
                                                         at android.app.Activity.performCreate(Activity.java:6374)
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
                                                         at android.app.ActivityThread.access$900(ActivityThread.java:182)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                         at android.os.Looper.loop(Looper.java:145)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6141)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                      Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.internal.Intrinsics" on path: DexPathList[[zip file "/data/app/a.b.c.com.kotlinplayground-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
                                                         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                         at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                         at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                         at a.b.c.com.logic.SubClass.&lt;init&gt;(SubClass.kt) 
                                                         at a.b.c.com.kotlinplayground.MainActivity.onCreate(MainActivity.kt:39) 
                                                         at android.app.Activity.performCreate(Activity.java:6374) 
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767) 
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879) 
                                                         at android.app.ActivityThread.access$900(ActivityThread.java:182) 
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                         at android.os.Looper.loop(Looper.java:145) 
                                                         at android.app.ActivityThread.main(ActivityThread.java:6141) 
                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                         at java.lang.reflect.Method.invoke(Method.java:372) 
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
                                                      Suppressed: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
                                                         at java.lang.Class.classForName(Native Method)
                                                         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                              ... 16 more
                                                      Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
  </code></pre>
  
  <p>The only way I can get it to work is if I do this:</p>
  
  <pre><code>class SubClass(pref : String?)  {
      fun theSubClassMethod() : String {
          return "The subclass method"
      }
  }
  </code></pre>
  
  <p>Notice the "?" question mark in the parameter, without it I can't get the code to work, but the question is why? why doesn't it work without it and how come every tutorial shows the parameter without the question mark and they don't mention anything about it... am I missing something?</p>
  
  <p>This is the way I use it:</p>
  
  <pre><code>val subClass = SubClass("ZZZ")
  </code></pre>
  
  <p><strong>Note:</strong> If the parameter in the constructor is an Int/Boolean, etc it works fine seems to happen only with objects.</p>