2017-04-21 2 views
0

Hallo an alle, ich habe ein seltsames Problem in meinem Android Studio, während ich ein komplett neues Navigationsschubladen-Projekt starte. Die Anwendung abstürzt, während die MainActivity mit einem Fehler beginnenNoSuchFieldError in der Navigationsschubladen-Aktivität

04-21 17:23:30.588 15257-15257/brsnc.infotech.dos.com.test E/AndroidRuntime: FATAL EXCEPTION: main 
    Process: brsnc.infotech.dos.com.test, PID: 15257 
    java.lang.NoSuchFieldError: No static field title of type I in class Landroid/support/v7/appcompat/R$id; or its superclasses (declaration of 'android.support.v7.appcompat.R$id' appears in /data/app/brsnc.infotech.dos.com.test-2/base.apk) 
    at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:481) 
    at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:324) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:285) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at brsnc.infotech.dos.com.test.MainActivity.onCreate(MainActivity.java:22) 
    at android.app.Activity.performCreate(Activity.java:5966) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2517) 
    at android.app.ActivityThread.access$800(ActivityThread.java:162) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:189) 
    at android.app.ActivityThread.main(ActivityThread.java:5530) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) 

Das Seltsame es nur passiert mit Navigationsleiste Aktivität. Ich habe es mit anderen Aktivitäten versucht und sie funktionieren gut.

Hier ist meine build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "brsnc.infotech.dos.com.test" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.1.1' 
    compile 'com.android.support:design:25.1.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    testCompile 'junit:junit:4.12' 
} 

UPDATE Hier ist meine Layout-Dateien.

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> 

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="brsnc.infotech.dos.com.test.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

content_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="brsnc.infotech.dos.com.test.MainActivity" 
    tools:showIn="@layout/app_bar_main"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/nav_header_height" 
    android:background="@drawable/side_nav_bar" 
    android:gravity="bottom" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     app:srcCompat="@android:drawable/sym_def_app_icon" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:text="Android Studio" 
     android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="[email protected]" /> 

</LinearLayout> 
+0

Haben Sie versucht, das Projekt zu säubern und neu aufzubauen? Das könnte tatsächlich lösen ... Auch würde ich versuchen, Datei-> Caches ungültig und Neustart –

+0

ich nicht nur neu erstellen, aber ich versuchte auch mit einem neuen Projekt, die mir das gleiche Ergebnis. – Arpan

+0

Möglicherweise gibt es ein Problem im Layout, können Sie es zeigen? –

Antwort

1

Möglicherweise sind Ihre SDK tools nicht updated. Zum Android SDK Manager und aktualisieren unten Dinge:

  1. Android SDK Werkzeuge
  2. Android SDK Build-Tools
  3. Android SDK-Plattform-Werkzeuge
  4. Android Support-Repository

Schließlich Clean und Rebuild Ihre Projekt und Run wieder.

Ich hoffe, dies wird das Problem lösen.

+1

durch Aktualisierung Android Support Repository hat den Trick. danke – Arpan

+0

Glücklich zu wissen, dass. Wenn meine Antwort sinnvoll erscheint, geben Sie bitte eine Stimme ab. Lesen Sie http://stackoverflow.com/help/someone-answers Vielen Dank im Voraus – FAT

Verwandte Themen