Skip to content

Commit e6588b5

Browse files
committed
fixed fragment crash
1 parent a39f645 commit e6588b5

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ dependencies {
3737
implementation fileTree(dir: 'libs', include: ['*.jar'])
3838
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3939
implementation 'androidx.appcompat:appcompat:1.3.0'
40-
implementation 'androidx.core:core-ktx:1.5.0'
40+
implementation 'androidx.core:core-ktx:1.6.0'
4141
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
4242
testImplementation 'junit:junit:4.13.2'
43-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
44-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
45-
implementation 'com.google.android.material:material:1.3.0'
43+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45+
implementation 'com.google.android.material:material:1.4.0'
46+
implementation 'androidx.fragment:fragment-ktx:1.3.5'
47+
4648

4749
// Architectural Components
4850
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
android:roundIcon="@mipmap/ic_launcher_round"
1212
android:supportsRtl="true"
1313
android:theme="@style/Theme.MVVMNews">
14+
1415
<activity android:name=".ui.MainActivity">
1516
<intent-filter>
1617
<action android:name="android.intent.action.MAIN" />

app/src/main/java/com/sijanneupane/mvvmnews/ui/MainActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.sijanneupane.mvvmnews.ui
33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import androidx.lifecycle.ViewModelProvider
6+
import androidx.navigation.fragment.NavHostFragment
67
import androidx.navigation.fragment.findNavController
78
import androidx.navigation.ui.setupWithNavController
89
import com.sijanneupane.mvvmnews.R
@@ -21,8 +22,9 @@ class MainActivity : AppCompatActivity() {
2122
val repository= NewsRepository(ArticleDatabase(this))
2223
val viewModelProviderFactory= NewsViewModelProviderFactory(repository)
2324
viewModel= ViewModelProvider(this, viewModelProviderFactory).get(NewsViewModel::class.java)
24-
25-
bottomNavigationView.setupWithNavController(newsNavHostFrag.findNavController())
25+
val navHostFragment= supportFragmentManager.findFragmentById(R.id.newsNavHostFrag) as NavHostFragment
26+
val navController= navHostFragment.navController
27+
bottomNavigationView.setupWithNavController(navController)
2628

2729

2830
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
app:layout_constraintStart_toStartOf="parent"
1717
app:layout_constraintTop_toTopOf="parent">
1818

19-
<fragment
19+
<androidx.fragment.app.FragmentContainerView
2020
android:id="@+id/newsNavHostFrag"
2121
android:name="androidx.navigation.fragment.NavHostFragment"
2222
android:layout_width="match_parent"

app/src/main/res/navigation/news_nav_graph.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:id="@+id/news_nav_graph.xml"
4+
android:id="@+id/news_nav_graph"
55
app:startDestination="@id/breakingNewsFragment">
66

77
<fragment

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath "com.android.tools.build:gradle:4.2.1"
9+
classpath 'com.android.tools.build:gradle:4.2.2'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
1212

0 commit comments

Comments
 (0)