【发布时间】:2016-05-27 05:41:25
【问题描述】:
我正在开发一个我编写应用程序类的应用程序。因此,我的 navigation drawer header menu 无法正常工作。它在Layout 和textview 上显示Nullpointer 异常
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
}
这是我使用的应用程序类,因为我使用了multidexenabled true。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Base.Theme.DesignDemo">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:id="@+id/fragment_container">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"
android:background="#FFFFFF"/>
但是由于我的 xml 中的那个应用程序类无法工作它给null pointer exception in
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"
android:background="#FFFFFF"/>
app:headerLayout="@layout/nav_header" is not working i am using component from it but in java class i get null pointer exception
【问题讨论】:
-
如何断言导航视图由于 Application 类而被禁用或不可见?
-
这是可见的,但是当我初始化文本视图和线性布局时,我得到空指针异常
标签: android