udacity / andfun-kotlin-gdg-finder

Apache License 2.0
34 stars 130 forks source link

Broken code does not allow the application to be launched #23

Open MinionAttack opened 1 year ago

MinionAttack commented 1 year ago

Hi,

After downloading the code from the master, final or starter-code branches the application does not start. I'm going to write about the master branch, as this is the branch I use to follow the videos.

  1. In home_fragment, fragment_gdg_list.xml and list_item.xml there is an incorrect style identifier:

"@dimen/spacing_normal" must be changed to "@dimen/normal_spacing"

  1. After solving that problem, when I start the application there is an error that makes the application crash. I've tried to fix it but I can't because I'm just starting to learn Android.
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.android.gdgfinder, PID: 4520
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.gdgfinder/com.example.android.gdgfinder.MainActivity}: java.lang.IllegalStateException: Activity com.example.android.gdgfinder.MainActivity@7f0df17 does not have a NavController set on 2131362118
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
        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:2307)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.IllegalStateException: Activity com.example.android.gdgfinder.MainActivity@7f0df17 does not have a NavController set on 2131362118
        at androidx.navigation.Navigation.findNavController(Navigation.kt:50)
        at androidx.navigation.ActivityKt.findNavController(Activity.kt:31)
        at com.example.android.gdgfinder.MainActivity.setupNavigation(MainActivity.kt:41)
        at com.example.android.gdgfinder.MainActivity.onCreate(MainActivity.kt:23)
        at android.app.Activity.performCreate(Activity.java:8305)
        at android.app.Activity.performCreate(Activity.java:8284)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
        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:2307) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7872) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Disconnected from the target VM, address: 'localhost:37127', transport: 'socket'

How can I fix this problem so that the application works?

Regards.

Dakrain commented 1 year ago

Same issue

Dakrain commented 1 year ago

I changed the FragmentContainerView in activity_main.xml to fragment and it worked.

ahmdaliielsayed commented 1 year ago

First, you should update jcenter() into mavenCentral() in the build.gradle(Project level) Then check about the versions of libraries as follow

ext {
        // Versions for all the dependencies we plan to use. It's particularly useful for Kotlin and
        // navigation where the versions of the plugin need to be the same as the version of the
        // library defined in the app Gradle file
        version_gradle = "4.0.1"
        version_core = "1.9.0"
        version_kotlin = "1.3.72"
        version_kotlin_coroutines = "1.6.4"
        version_lifecycle_extensions = "2.2.0"
        version_moshi = "1.14.0"
        version_navigation = "2.5.3"
        version_constraint_layout = "2.1.4"
        version_glide = "4.15.1"
        version_retrofit = "2.9.0"
        version_retrofit_coroutines_adapter = "0.9.2"
        version_recyclerview = "1.2.0-alpha05"
        version_material = "1.1.0-alpha04"
        version_play_services = "17.0.0"
}

After that, you should increase the targetSdkVersion and compileSdkVersion to 33 in the build.gradle(Module:app) You could also modify the way defining the plugins as follow

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs'
}

After that, in the AndroidManifest.xml you need to ask for ACCESS_COARSE_LOCATION as it's required from Android API 33 and add android:exported="true" to the activity If you don't add any fonts in the app yet as it's the starter code then you must delete the meta-data

<meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />

Are you sure that you inflate the fragment correctly? The starter code inflates the fragment without using data binding or view binding. After you use data binding the onCreateView() should return binding.root

I think after you follow these steps it should work for you.

KarthiAru commented 3 months ago

I changed the FragmentContainerView in activity_main.xml to fragment and it worked.

This solved the app crash for me. Thanks.