使用导航抽屉时的Java运行时异常

时间:2015-11-03 20:44:53

标签: android runtime navigation-drawer

我正在尝试运行我的项目,但它在加载时崩溃了。我有我的proguard,因为它是迄今为止所有问题的来源和我的错误。

我试过了:

  • 重新安装android studio
  • clean build
  • 重建项目
  • 删除对缺失类的已知引用

我的proguard文件如下所示:

-dontwarn android.net.http.**
-dontwarn org.apache.http.**
-dontwarn org.apache.httpcomponents.**
-dontwarn org.apache.commons.codec.**
-dontwarn com.android.build.transform.api.**
-dontwarn org.apache.commons.io.**
-dontwarn org.apache.lang.**
-dontwarn org.apache.commons.**
-dontwarn org.bouncycastle.**
-dontwarn org.joda.**
-dontwarn au.com.bytcode.opencsv.**
-dontwarn java.beans.**
-dontwarn com.google.**
-dontwarn java.lang.invoke.**
-dontwarn com.playerize.**
-dontwarn com.parse.**
-dontwarn org.apache.lang.**
-dontwarn org.apache.commons.**
-dontwarn com.chartboost.**
-dontwarn dagger.**
-dontwarn com.supersonic.**
-dontwarn org.bouncycastle.**
-dontwarn android.webkit.JavascriptInterface

错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intellidev.bitrichpro/com.intellidev.bitrichpro.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.NavigationView
11-03 15:28:45.678 6098-6098/? E/AndroidRuntime:     at com.intellidev.bitrichpro.MainActivity.onCreate(Unknown Source)
    enter code here

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:id="@+id/drawer_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:fitsSystemWindows="true" tools:openDrawer="start">

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

    <android.support.design.widget.NavigationView android:id="@+id/nav_view"
        android:layout_width="wrap_content" android:layout_height="match_parent"
        android:layout_gravity="start" android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

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

新错误:

Unable to start activity ComponentInfo{com.intellidev.bitrichpro/com.intellidev.bitrichpro.MainActivity}: java.lang.IllegalArgumentException: Default constructor for class com.b.oc is not accessible

1 个答案:

答案 0 :(得分:0)

请将以下内容添加到您的proguard文件中。

# keep classes with the `View(Context, Attributes)` constructor
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

# keep classes with the `View(Context, Attributes, int)` constructor
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

# keep methods that accept a view as their argument.
# This would be the case if you set an onclick from an xml file
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# keep all of the design library
-keep class android.support.design.** { *; }

# keep all android classes
-keep class android.** { *; }

# keep all class members, don't rename methods
-keepclassmembers class android.** { *; }
-dontobfuscate