应用程序应该有一个从左侧拉出来并显示各种活动的导航抽屉,但是一旦导航栏添加到XML activity_homescreen doc,应用程序就会在启动后立即崩溃。
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如下(注释掉导航视图小部件)...
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>
除了导航抽屉没有包含/工作之外,一切正常。有没有人有这个问题,甚至更好,有谁知道如何解决它?我需要导航抽屉工作,但它似乎崩溃我的应用程序。
logcat溢出了最大字符数,所以这里是github gist。
答案 0 :(得分:2)
肯定是你的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]