2015-12-29 67 views
3

美好的一天,你能幫我一個忙嗎?編譯/在模擬器上運行我的代碼時出現此錯誤。這是我以前製作的示例教程。我用分鐘目標API - 15和編譯最新gradle這個 'com.android.support:design:23.0.0'類未找到Android支持設計小工具NavigationView

http://www.android4devs.com/2015/06/navigation-view-material-design-support.html

代碼錯誤:

AndroidRuntime:了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.eccp.projects .ecosavers.ecosavers/com.eccp.projects.ecosavers.ecosavers.activities.MainActivity}:android.view.InflateException:二進制XML文件行#29:二進制XML文件行#29:錯誤充氣類android.support.design。 widget.NavigationView 12-29 06:43:39.409 3448-3448/com.eccp.projects.ecosavers.ecosavers E/AndroidRuntime:在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)

E/AndroidRuntime:產生的原因:android.view.InflateException :二進制XML文件行#29:二進制XML文件行#29:錯誤充氣類android.support.design.widget.NavigationView

這裏是我的代碼:MainActivity.java

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    //SET my own toolbar 
    toolbar = (Toolbar) findViewById(R.id.tool_bar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 
    getSupportActionBar().setHomeButtonEnabled(true); 

    mNavigationView = (NavigationView) findViewById(R.id.navigation_view); 

    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 

     @Override 
     public boolean onNavigationItemSelected(MenuItem menuItem) { 
      if (menuItem.isChecked()) menuItem.setChecked(false); 
      else menuItem.setChecked(true); 

      //Closing drawer on item click 
      mDrawerlayout.closeDrawers(); 

      //Check to see which item was being clicked and perform appropriate action 
      switch (menuItem.getItemId()) { 


       //Replacing the main content with ContentFragment Which is our Inbox View; 
       case R.id.events: 
        Toast.makeText(getApplicationContext(), "Inbox Selected", Toast.LENGTH_SHORT).show(); 
        Eco_events fragment = new Eco_events(); 
        android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 
        fragmentTransaction.replace(R.id.frame, fragment); 
        fragmentTransaction.commit(); 
        return true; 

       // show a toast on click 

       case R.id.activities: 
        Toast.makeText(getApplicationContext(), "Send Selected", Toast.LENGTH_SHORT).show(); 
        return true; 
       case R.id.spam: 
        Toast.makeText(getApplicationContext(), "Spam Selected", Toast.LENGTH_SHORT).show(); 
        return true; 
       default: 
        Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); 
        return true; 

      } 
     } 
    }); 

    // Initializing Drawer Layout and ActionBarToggle 
    mDrawerlayout = (DrawerLayout) findViewById(R.id.drawer); 
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerlayout, toolbar, R.string.drawerOpened, R.string.drawerOpened) { 

     @Override 
     public void onDrawerClosed(View drawerView) { 
      // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank 
      super.onDrawerClosed(drawerView); 
     } 

     @Override 
     public void onDrawerOpened(View drawerView) { 
      // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank 
      super.onDrawerOpened(drawerView); 
     } 
    }; 

    //Setting the actionbarToggle to drawer layout 
    mDrawerlayout.setDrawerListener(mDrawerToggle); 

    //calling sync state is 
    mDrawerToggle.syncState(); 


} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    return super.onOptionsItemSelected(item); 
} 

XML:activity_main.xml

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context=".MainActivity"> 

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    > 
    <include 
     android:id="@+id/tool_bar" 
     layout="@layout/toolbar" 
     /> 
    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </FrameLayout> 
</LinearLayout> 
<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_view" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:layout_gravity="start" 
    app:headerLayout="@layout/header" 
    app:menu="@menu/drawer" 
    /> </android.support.v4.widget.DrawerLayout> 
+1

你可以發佈完整的stacktrace嗎? –

+0

你可以發佈應用程序build.gradle文件嗎? – Raghunandan

+0

@Raghunandan - 你是什麼意思?我用來編譯的gradle列表? – RoCk

回答

0

,因爲你所需要的設計支持庫您收到此錯誤。

打開SDK管理器,下載Android的支持庫,比你可以在這裏找到庫的最後一個版本:

<android-sdk>/extras/android/m2repository/com/android/support/design/23.0.1/design-23.0.1.aar 

拷貝在你的庫目錄,然後依賴添加到您的build.gradle:

repositories { 
    flatDir { 
     dirs 'libs' 
    } 
} 

dependencies { 
    compile 'android.support.design:design:[email protected]' 
} 
+0

這是你的意思嗎?編譯'com.android.support:design:23.0.0' 我已經這個lib。和gradle已經編譯好了:( 。 我將在YouTube上搜索如何發佈此堆棧跟蹤。 – RoCk

12

按照這個步驟:

  1. 右擊t點擊您的Project->Open Module Settings
  2. 然後打開「依存關係」選項卡。
  3. 單擊+符號,然後選擇庫依賴關係。您將看到一個名爲「選擇庫依賴關係」的彈出窗口。
  4. 那裏輸入「com.android.support」。然後點擊搜索圖標。

  • 現在選擇設計庫。並點擊確定。
  • 2

    謝謝您的關注,我很感激。我終於找到了(我的)這個問題的答案。

    錯誤充氣類android.support.design.widget。NavigationView#28或#29

    適用於我的解決方案是,您必須匹配您的support design library和您的支持AppCompat Library。在gradle這個模塊,

    Locate Gradle

    變化gradle這個版本(你需要的庫中沒有。)您也可以找到,我已經給出了鏈接的最新gradle這個身材,但我建議您在gradle這個模塊中檢查(第二張圖片,因爲他們是第一次更新gradle build,然後在我的gradle模塊中 - compile: ...已經被突出顯示,這意味着有一個更新的版本,只需更改編號,例如24.0.0如果編譯穩定而不是預覽),同時,我的是23.1.1

    - >more gradle lib- gradleplease.appspot.com

    compile 'com.android.support:appcompat-v7:23.1.1'

    compile 'com.android.support:design:23.1.1'

    Gradle Dependencies

    :)這對我的作品!

    觀察(對於我來說,當我改變了/解決了這個錯誤,價值23.x.x):如果你的support-designAppCompat-lib產生#28,如果你AppCompat匹配不匹配support-design產生#29。試試吧,也許我換了#。