2017-10-12 44 views
-1

錯誤是 - java.lang.NoClassDefFoundError:失敗的解決方案:Landroid/support/v7/widget/TintManager;在Android中使用選項卡式活動時發生錯誤

我的代碼片段 -

public class TaberActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener { 

    //This is our tablayout 
    private TabLayout tabLayout; 

    //This is our viewPager 
    private ViewPager viewPager; 

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

     //Adding toolbar to the activity 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     //Initializing the tablayout 
     tabLayout = (TabLayout) findViewById(R.id.tabLayout); 

     //Adding the tabs using addTab() method 
     tabLayout.addTab(tabLayout.newTab().setText("Tab1")); 
     tabLayout.addTab(tabLayout.newTab().setText("Tab2")); 
     tabLayout.addTab(tabLayout.newTab().setText("Tab3")); 
     tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); 

     //Initializing viewPager 
     viewPager = (ViewPager) findViewById(R.id.pager); 

     //Creating our pager adapter 
     Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount()); 

     //Adding adapter to pager 
     viewPager.setAdapter(adapter); 

     //Adding onTabSelectedListener to swipe views 
     tabLayout.setOnTabSelectedListener(this); 
    } 

    @Override 
    public void onTabSelected(TabLayout.Tab tab) { 
     viewPager.setCurrentItem(tab.getPosition()); 
    } 

    @Override 
    public void onTabUnselected(TabLayout.Tab tab) { 

    } 

    @Override 
    public void onTabReselected(TabLayout.Tab tab) { 

    } 
} 

我無法弄清楚我要去哪裏錯了。如果有人能夠爲我提供解決方案,這將非常有幫助。

編輯 - 有以下搖籃腳本:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.1" 
    defaultConfig { 
     applicationId "com.avidprogrammers.atlantiquemoney" 
     minSdkVersion 15 
     targetSdkVersion 26 
     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:26.+' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.android.support:cardview-v7:23.3.0' 
    compile 'com.android.support:design:23.1.1' 
    testCompile 'junit:junit:4.12' 
} 

已經在應用上述gradle這個。

+0

更換你格拉德爾發表您的'gradle'太 – pleft

+0

顯示您的gradle構建依賴 – EpicPandaForce

+0

C精益項目或無效緩存並重新啓動 –

回答

1

你的程序兼容性依賴的版本不匹配。您一起使用v26和v23。

compile 'com.android.support:appcompat-v7:26.+' 
compile 'com.android.support.constraint:constraint-layout:1.0.2' 
compile 'com.android.support:cardview-v7:23.3.0' 
compile 'com.android.support:design:23.1.1' 

您應該更改cardview和設計以使用26.x.y以及。

1

更新您的support依賴於最新的:

compile 'com.android.support:appcompat-v7:26.+' 
compile 'com.android.support:cardview-v7:26.+' 
compile 'com.android.support:design:26.+' 
1

使用本

compile 'com.android.support:design:26.+' 
compile 'com.android.support:cardview-v7:26.+' 

,而不是這個

compile 'com.android.support:design:23.1.1' 
compile 'com.android.support:cardview-v7:23.3.0' 
1


apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.0" 
    defaultConfig { 
     applicationId "com.avidprogrammers.atlantiquemoney" 
     minSdkVersion 15 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions { 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/DEPENDENCIES' 
    } 
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:design:26.0.0-alpha1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    complie 'com.android.support:cardview-v7:26.0.0-alpha1' 
    testCompile 'junit:junit:4.12' 
} 
相關問題