简体   繁体   English

无法在Android Studio中解析符号fab

[英]Cannot resolve symbol fab in Android Studio

I am developing an app but I am having an issue with a piece of code. 我正在开发应用程序,但是我遇到了一段代码问题。 The same piece of code is giving me the same error for a few different pages. 同一段代码在几个不同的页面上给了我相同的错误。

The code is as follows: 代码如下:

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

    buttonSignIn = (Button) findViewById(R.id.buttonSignIN);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();

            buttonSignIn.setOnClickListener(this);
        }
    });
}}

It gives me an error on the line below saying it cannot resolve symbol fab FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 它在下面的行上给我一个错误,表明它无法解析符号fab FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

You probably deleted the fab in your activity_main: 您可能在activity_main中删除了工厂:

这个

If that's the case, and you really don't need the fab, you probably just need to delete this piece of code: 如果是这样,并且您确实不需要fab,则可能只需要删除以下代码即可:

buttonSignIn = (Button) findViewById(R.id.buttonSignIN);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();

        buttonSignIn.setOnClickListener(this);
    }
});

add the support:design in build.gradle: module app to dependencies this will fix it 在build.gradle:模块应用程序中将support:design添加到依赖项中,这将对其进行修复

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

will look like this : 看起来像这样:

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:design:26.+'
testCompile 'junit:junit:4.12'

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM