构建错误:无法找到特定的资源

时间:2021-09-13 09:44:23

when i run the below code i get this error and get it with multiple positions but with this code usually mean when i write code like this

当我运行下面的代码时,我得到了这个错误并得到了多个位置,但是使用这个代码通常意味着当我编写这样的代码时

C:\Users\saad\Desktop\Sa2d\Android\JustJava\app\src\main\java\com\example\android\justjava\MainActivity.java
Error:(21, 76) error: cannot find symbol variable fab
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

this my code on "content_main.xml"

这是我在"content_main.xml"上的代码

    `<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    android:orientation="vertical"
    tools:showIn="@layout/activity_main">

   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Quantity"/>
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="0"/>
   <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Order"
       android:id="@+id/button" />
</LinearLayout>`

and this my code on "MainActivity.java" i am mark the error line with *

这是我的“主活动”代码。java“我用*标记错误行

`*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();
        }
    });`

what is the solution for this problem ???

解决这个问题的办法是什么?

5 个解决方案

#1


2  

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//etc..

Is refer to FloatingActionButton, so probably you have deleted the code on xml file and then you have to delete the code (java) relative to Fab or you can add:

是FloatingActionButton,所以您可能已经删除了xml文件上的代码,然后您必须删除与Fab相关的代码(java),或者您可以添加:

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

on your layout.xml

在你layout.xml

#2


2  

Add a floating action button to your layout called fab.

向布局添加一个名为fab的浮动操作按钮。

Example:

例子:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

#3


1  

Your layout doesn't have any FloatingActionButton with id fab.

你的布局没有任何浮动的actionbutton与id fab。

#4


0  

In your build.gradle file, add this:

在您的构建。gradle文件,添加:

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

more reference

更多的参考

FloatingActionButton example with Support Library

使用支持库的FloatingActionButton示例

#5


-1  

Try adding following Gradle dependency:

尝试添加以下等级依赖性:

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

编译“com.android.support:设计:22.2.0”

followed by gradle sync.

其次是gradle同步。

#1


2  

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//etc..

Is refer to FloatingActionButton, so probably you have deleted the code on xml file and then you have to delete the code (java) relative to Fab or you can add:

是FloatingActionButton,所以您可能已经删除了xml文件上的代码,然后您必须删除与Fab相关的代码(java),或者您可以添加:

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

on your layout.xml

在你layout.xml

#2


2  

Add a floating action button to your layout called fab.

向布局添加一个名为fab的浮动操作按钮。

Example:

例子:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

#3


1  

Your layout doesn't have any FloatingActionButton with id fab.

你的布局没有任何浮动的actionbutton与id fab。

#4


0  

In your build.gradle file, add this:

在您的构建。gradle文件,添加:

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

more reference

更多的参考

FloatingActionButton example with Support Library

使用支持库的FloatingActionButton示例

#5


-1  

Try adding following Gradle dependency:

尝试添加以下等级依赖性:

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

编译“com.android.support:设计:22.2.0”

followed by gradle sync.

其次是gradle同步。