Your Second Kotlin Android App - Part 33: Running the | Ray Wenderlich

The tablet layout is all set to go, but there are errors that need to be resolved. This video shows you how to fix them.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4534-your-second-kotlin-android-app/lessons/33

There are many errors in the code which you haven’t resolved. As the result on this step the application isn’t compiled.

MainActivity: Smart cast to ‘ListDetailFragment’ is impossible, because ‘listFragment’ is a mutable property that could have been changed by this time

ListDetailActivity: a lot fo errors, the code isn’t upgraded.

Disappointing…

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Even I get MainActivity: Smart cast to ‘ListDetailFragment’ is impossible, because ‘listFragment’ is a mutable property that could have been changed by this time

@onkeltem @vieony Thank you for the heads up! We will fix these in the next version.

So much is missing in this which makes this very upsetting. Was hoping for a fully cleaned setup and though it started out great it has crashed and burned when it has come to the end. Kind of sad b/c it loses a lot of what I was hoping for right when I needed it the most.

@vegas3416 What errors do you get exactly?

In my case app is working fine on phone (emulator and real device) but is crashing on the Pixel C emulator. Here is the exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{ai.smac.listmaker/ai.smac.listmaker.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘void com.google.android.material.floatingactionbutton.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)’ on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void com.google.android.material.floatingactionbutton.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)’ on a null object reference
at ai.smac.listmaker.MainActivity.onCreate(MainActivity.kt:34)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Please suggest

Thanks

It appears that you are missing a floating action button. The code is trying to see the click listener, but since it’s null, it’s crashing the program. I’m guessing you forgot to add the floating action button to the layout. That’s the first place that I’d look.