当我尝试构建我的android项目时,我得到了这个错误
错误:(8,37)错误:包android.support.design.widget没有 存在错误:(18,9)错误:找不到符号类TabLayout 错误:(18,32)错误:找不到符号类TabLayout错误:(21, 33)错误:找不到符号变量TabLayout错误:(27,56)错误: 包TabLayout不存在错误:(48,36)错误:找不到 符号变量菜单错误:(28,57)错误:包TabLayout没有 存在错误:任务执行失败 ':应用程序:compileDebugJavaWithJavac'
编译失败;请参阅编译器错误输出以获取详细信错误:(55,23)错误:找不到符号变量action_settings
这是我的代码
package com.chaos.creativo;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.design.widget.TabLayout;
/**
* Created by ahmed on 3/7/2016.
*/
public class Signin_up extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signing_up);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("SIGN IN"));
tabLayout.addTab(tabLayout.newTab().setText("SIGN UP"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PageAdapter adapter = new PageAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@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) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的build.gradle
> apply plugin: 'com.android.application'
>
> android {
> compileSdkVersion 23
> buildToolsVersion "23.0.2"
>
> defaultConfig {
> applicationId "com.chaos.creativo"
> minSdkVersion 18
> targetSdkVersion 23
> versionCode 1
> versionName "1.0"
> }
> buildTypes {
> release {
> minifyEnabled false
> proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
> }
> } }
>
> dependencies {
> compile fileTree(dir: 'libs', include: ['*.jar'])
> testCompile 'junit:junit:4.12'
> compile 'com.android.support:appcompat-v7:23.1.1'
> compile 'com.google.android.gms:play-services-ads:8.4.0'
> compile 'com.google.android.gms:play-services-identity:8.4.0'
> compile 'com.firebase:firebase-client-android:2.3.1'
> compile 'com.google.android.gms:play-services-gcm:8.4.0'
> compile 'com.android.support:support-v4:23.2'
> compile 'com.android.support:design:23.2' }
答案 0 :(得分:17)
如果您正在使用android studio,请将以下内容放入gradle文件并重建。
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'
如果版本23.2.1不支持,请使用23.1.1
答案 1 :(得分:3)
我通过添加以下内容解决了同样的错误:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'
}
答案 2 :(得分:2)
对于API 25,这对我有用:
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
答案 3 :(得分:2)
在API 26上,这有效:
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:design:26.+'
答案 4 :(得分:1)
如果您将支持库与不允许的 AndroidX 库混合使用。删除支持库,然后使用 AndroidX 。要正确迁移AndroidX,请执行以下步骤: 1 。选择重构->迁移到AndroidX ** 2 。按Do Refatcor **
答案 5 :(得分:0)
替换
implementation 'com.android.support:support-v4:28.0.0'
使用
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
在您的build.gradle中