错误膨胀类 android.support.design.widget.NavigationView [启动时崩溃] [英] Error Inflating class android.support.design.widget.NavigationView [Crash on Startup]

查看:49
本文介绍了错误膨胀类 android.support.design.widget.NavigationView [启动时崩溃]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用应该有一个从左侧拉出并显示各种活动的导航抽屉,但是一旦将导航栏添加到 XML activity_homescreen 文档中,应用一启动就会崩溃.

The app is supposed to have a navigation drawer that pulls out from the left and shows the various activities, but once the navigation bar is added to the XML activity_homescreen doc, the app crashes as soon as it starts.

HomeScreen.java

package com.t99sdevelopment.centralized;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Toolbar;

public class HomeScreen extends AppCompatActivity {

    /*
    Intent intentHome = new Intent(this, HomeScreen.class);
    Intent intentAnnouncements = new Intent(this, AnnouncementsScreen.class);
    Intent intentSchedule = new Intent(this, ScheduleScreen.class);
    Intent intentCalendar = new Intent(this, CalendarScreen.class);
    Intent intentContactBook = new Intent(this, ContactBookScreen.class);
    Intent intentSportsSchedule = new Intent(this, SportsScheduleScreen.class);
    Intent intentFrontAndCentral = new Intent(this, FrontAndCentralScreen.class);
    Intent intentMap = new Intent(this, MapScreen.class);
    Intent intentAccount = new Intent(this, AccountScreen.class);
    */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homescreen);
        setTheme(R.style.AppTheme);
    }

    /*
    private void goToHome(View view){ startActivity(intentHome ); }
    private void goToAnnouncements(View view){ startActivity(intentAnnouncements ); }
    private void goToSchedule(View view){ startActivity(intentSchedule); }
    private void goToCalendar(View view){ startActivity(intentCalendar); }
    private void goToContactBook(View view){ startActivity(intentContactBook); }
    private void goToSportsSchedule(View view){ startActivity(intentSportsSchedule); }
    private void goToFrontAndCentral(View view){ startActivity(intentFrontAndCentral); }
    private void goToMap(View view){ startActivity(intentMap); }
    private void goToAccount(View view){ startActivity(intentAccount); }
    */
}

activity_homescreen.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
    android:background="@color/trojanBlack">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center_horizontal">

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/actionbar" />

        <ImageView
            android:id="@+id/ImageView_trojanHead"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="150dp"
            android:src="@drawable/trojan"
            android:scaleType="centerCrop" />

        <TextView
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginTop="100dp"
            android:text="School is"
            android:paddingTop="5dp"
            android:textSize="30sp"
            android:textColor="@color/trojanBlack"
            android:textAlignment="center"
            android:background="@drawable/schoolbutton"
            android:radius="5dp"/>

        <RelativeLayout
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginTop="-100dp">

            <Button
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:background="@drawable/refresh"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"/>

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_centerInParent="true"
                android:text="OPEN"
                android:textSize="40sp"
                android:textColor="@color/trojanBlack"
                android:textAlignment="center"
                android:paddingTop="45dp" />

        </RelativeLayout>

        <TextView
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:background="#FFFFFF"
            android:layout_marginTop="10dp" />

        <FrameLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:menu="@menu/navigationdraweritems"
        app:headerLayout="@layout/nav_header" />

</android.support.v4.widget.DrawerLayout>

使用这些文件,应用程序会崩溃,但如果我按如下方式更改 activity_homescreen.xml(注释掉导航视图小部件)...

With these files as is, the app crashes, but if I change the activity_homescreen.xml as follows (commenting out the navigation view widget)...

activity_homescreen.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
    android:background="@color/trojanBlack">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center_horizontal">

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/actionbar" />

        <ImageView
            android:id="@+id/ImageView_trojanHead"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="150dp"
            android:src="@drawable/trojan"
            android:scaleType="centerCrop" />

        <TextView
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginTop="100dp"
            android:text="School is"
            android:paddingTop="5dp"
            android:textSize="30sp"
            android:textColor="@color/trojanBlack"
            android:textAlignment="center"
            android:background="@drawable/schoolbutton"
            android:radius="5dp"/>

        <RelativeLayout
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_marginTop="-100dp">

            <Button
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:background="@drawable/refresh"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"/>

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_centerInParent="true"
                android:text="OPEN"
                android:textSize="40sp"
                android:textColor="@color/trojanBlack"
                android:textAlignment="center"
                android:paddingTop="45dp" />

        </RelativeLayout>

        <TextView
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:background="#FFFFFF"
            android:layout_marginTop="10dp" />

        <FrameLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <!--
    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:menu="@menu/navigationdraweritems"
        app:headerLayout="@layout/nav_header" />
    -->

</android.support.v4.widget.DrawerLayout>

一切正常,除了导航抽屉没有被包含/工作.有没有人遇到过这个问题,或者更好,有没有人知道如何解决它?我需要导航抽屉工作,但它似乎使我的应用程序崩溃.

Everything works just fine, with the exception of the navigation drawer not being included/working. Has anyone had this issue, or even better, does anyone know how to fix it? I need the navigation drawer working, but it seems to crash my app.

logcat 溢出了最大字符数,所以这里是 github 要点.>

The logcat spilled over the maximum number of characters, so here's the github gist.

推荐答案

很明显是你的 logcat 中缺少方法的问题:

Most definitely a problem with a missing method, from your logcat :

Caused by: android.view.InflateException: Couldn't resolve menu item onClick handler goToHome in class com.t99sdevelopment.centralized.HomeScreen
Caused by: java.lang.NoSuchMethodException: goToHome [interface android.view.MenuItem]

这篇关于错误膨胀类 android.support.design.widget.NavigationView [启动时崩溃]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆