Java 错误包 android.support.design.widget 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35843655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:10:11  来源:igfitidea点击:

error package android.support.design.widget does not exist

javaandroid

提问by zod101

when i try to build my android project i get this errors

当我尝试构建我的 android 项目时,我收到此错误

Error:(8, 37) error: package android.support.design.widget does not exist Error:(18, 9) error: cannot find symbol class TabLayout Error:(18, 32) error: cannot find symbol class TabLayout Error:(21, 33) error: cannot find symbol variable TabLayout Error:(27, 56) error: package TabLayout does not exist Error:(48, 36) error: cannot find symbol variable menu Error:(28, 57) error: package TabLayout does not exist Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details. Error:(55, 23) error: cannot find symbol variable action_settings

错误:(8, 37) 错误:包android.support.design.widget 不存在错误:(18, 9) 错误:找不到符号类TabLayout 错误:(18, 32) 错误:找不到符号类TabLayout 错误: (21, 33) 错误:找不到符号变量TabLayout 错误:(27, 56) 错误:包TabLayout 不存在错误:(48, 36) 错误:找不到符号变量菜单错误:(28, 57) 错误:包TabLayout 不存在错误:任务 ':app:compileDebugJavaWithJavac' 的执行失败。

编译失败;有关详细信息,请参阅编译器错误输出。错误:(55, 23) 错误:找不到符号变量 action_settings

and this is my code

这是我的代码

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);
    }
}

my build.gradle

我的 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' }

采纳答案by Parsania Hardik

If you are using android studio then put following in gradle file and rebuild.

如果您使用的是 android studio,则将以下内容放入 gradle 文件并重建。

 compile 'com.android.support:support-v4:23.2.1'
 compile 'com.android.support:design:23.2.1'

If version 23.2.1 won't support, use 23.1.1

如果版本 23.2.1 不支持,请使用 23.1.1

回答by Hamid

I solved same error by adding this:

我通过添加这个解决了同样的错误:

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'
}

回答by j2abro

For API 25 this worked for me:

对于 API 25,这对我有用:

compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'

回答by Expert Ngobeni

On API 26 this works:

在 API 26 上,这有效:

    compile 'com.android.support:support-v4:26.+'
    compile 'com.android.support:design:26.+' 

回答by Rajneesh Raj

In case if you are mixing Supportlibrary with AndroidXlibrary which is not permissible. Remove supportlibrary and use AndroidX. To migrate AndroidX correctly follow below steps: 1.Select Refactor -> Migrate to AndroidX **2.Press Do Refatcor**

如果您将支持库与不允许的 AndroidX库混合使用。删除支持库并使用AndroidX。要正确迁移 AndroidX,请按照以下步骤操作: 1. 选择 Refactor -> Migrate to AndroidX **2.Press Do Refatcor**

回答by Ingo

Replace

代替

implementation 'com.android.support:support-v4:28.0.0'

with

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

in your build.gradle

在你的 build.gradle 中