Я пытаюсь реализовать базовую c панель навигации в моем приложении Android. Предполагается, что он появится в действии сразу после входа пользователя в систему. Однако мое приложение вылетает сразу после успешного входа в систему.
Я попробовал несколько методов, которые включали проверку местоположения моих доступных для рисования изображений, изменение зависимости и редактирование стилей. Кажется, ничего не работает.
Stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sehat20, PID: 6176
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sehat20/com.example.sehat20.PatientAfterLogin}: android.view.InflateException: Binary XML file line #46: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.InflateException: Binary XML file line #46: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:651)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.sehat20.PatientAfterLogin.onCreate(PatientAfterLogin.java:26)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.InflateException: Couldn't resolve menu item onClick handler OurAim in class com.example.sehat20.PatientAfterLogin
at androidx.appcompat.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:254)
at androidx.appcompat.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:482)
E/AndroidRuntime: at androidx.appcompat.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:530)
at androidx.appcompat.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:206)
at androidx.appcompat.view.SupportMenuInflater.inflate(SupportMenuInflater.java:128)
at com.google.android.material.navigation.NavigationView.inflateMenu(NavigationView.java:264)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:189)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:104)
... 28 more
Caused by: java.lang.NoSuchMethodException: OurAim [interface android.view.MenuItem]
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getMethod(Class.java:1690)
at androidx.appcompat.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:250)
... 35 more
Это мой xml файл.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PatientAfterLogin"
android:background="@color/brandColour"
android:id="@+id/dl">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:background="@drawable/logo">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="28dp"
android:text="Welcome to Sehat!"
android:textStyle="italic"
android:textColor="@color/textColor"
android:layout_marginTop="230dp">
</TextView>
</RelativeLayout>
</ScrollView>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/nav_view"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/navigation_menu">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Это build.gradle:
defaultConfig {
applicationId "com.example.sehat20"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:29.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:design:29.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
}
Эти это стили. xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="toolbarStyle">@style/CustomToolBarStyle</item>
</style>
<style name="CustomToolBarStyle" parent="@style/Widget.AppCompat.Toolbar">
<item name="titleTextColor">@color/textColor</item>
</style>
</resources>
Это меню навигации:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/nav_our_aim"
android:title="Home"
android:icon="@drawable/about_us"
android:onClick="OurAim">
</item>
<item android:id="@+id/nav_general_info"
android:title="Personal Information"
android:icon="@drawable/resume"
android:onClick="Info">
</item>
<item android:id="@+id/nav_results"
android:title="Test Results"
android:icon="@drawable/medical_result"
android:onClick="Results">
</item>
<item android:id="@+id/nav_reminder"
android:title="Check-up Reminders"
android:icon="@drawable/calendar"
android:onClick="Reminders">
</item>
<item android:id="@+id/nav_logout"
android:title="Log Out"
android:icon="@drawable/logout"
android:onClick="LogOut">
</item>
</menu>