Java runtime exception when using navigation drawer

随声附和 提交于 2019-12-25 03:52:50

问题


I am trying to run my project but it crashes upon load. I have my proguard here as it has been the source of all issues so far and my error below that.

I have tried:

  • reinstalling android studio
  • clean build
  • rebuild project
  • deleting known references to missing classes

My proguard file is as shown:

-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

Error:

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>

New error:

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:


Please add the following to your proguard file.

# 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


来源:https://stackoverflow.com/questions/33508722/java-runtime-exception-when-using-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!