Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

android studio 3.0 - Failed linking file resources

This is the java file that is giving the error

package com.example.daksh.timetable;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

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

        final Button mon_but,tue_but,wed_but,thur_but,fri_but;
        mon_but = (Button)findViewById(R.id.mon);
        tue_but = (Button)findViewById(R.id.tue);
        wed_but = (Button)findViewById(R.id.wed);
        thur_but = (Button)findViewById(R.id.thur);
        fri_but = (Button)findViewById(R.id.fri);
        final ImageView main_Image = (ImageView) findViewById(R.id.day);
        final int[] dayarray = {R.drawable.monday,R.drawable.tuesday,R.drawable.wednesday,R.drawable.thursday, R.drawable.friday};

        mon_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                main_Image.setImageResource(dayarray[0]);
            }

        });
        tue_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                main_Image.setImageResource(dayarray[1]);
            }
        });
        wed_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                main_Image.setImageResource(dayarray[2]);
            }
        });
        thur_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                main_Image.setImageResource(dayarray[3]);
            }
        });
        fri_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                main_Image.setImageResource(dayarray[4]);
            }
       });
   }
}

The errors that I am getting are as follows

Information:Gradle tasks [clean, :app:assembleDebug] C:ProjectsTimeTableappsrcmain eslayoutactivity_main.xml Error:error: resource android:attr/colorSwitchThumbNormal is private. Error:resource android:attr/colorSwitchThumbNormal is private. C:ProjectsTimeTableappsrcmain eslayout-landactivity_main.xml Error:error: resource android:attr/colorSwitchThumbNormal is private. Error:resource android:attr/colorSwitchThumbNormal is private. Error:failed linking file resources. Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Execution failed for task ':app:processDebugResources'. Failed to execute aapt Information:BUILD FAILED in 9s Information:9 errors Information:0 warnings Information:See complete output in console

This is the Activity_main.xml file

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/day"
        android:layout_width="0dp"
        android:layout_height="0dp"

        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:contentDescription="TODO"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintHorizontal_bias="0.519"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline2"
        app:layout_constraintVertical_bias="0.472"
        app:srcCompat="@drawable/monday" />

    <TextView
        android:id="@+id/textView"
        style="@style/Widget.AppCompat.TextView.SpinnerItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:fontFamily="serif"
        android:text="@string/message"
        android:textColor="?android:attr/colorSwitchThumbNormal"
        android:textSize="18sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/mon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="50dp"
        android:text="@string/monday"
        app:layout_constraintBottom_toTopOf="@+id/tue"
        app:layout_constraintStart_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/tue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="16dp"
        android:text="@string/tuesday"
        app:layout_constraintBottom_toTopOf="@+id/wed"
        app:layout_constraintStart_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintTop_toBottomOf="@id/mon" />

    <Button
        android:id="@+id/wed"
        android:layout_width="88dp"
        android:layout_height="48dp"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="16dp"
        android:text="@string/wednesday"
        app:layout_constraintBottom_toTopOf="@+id/thur"
        app:layout_constraintStart_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintTop_toBottomOf="@id/tue" />

    <Button
        android:id="@+id/thur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="16dp"
        android:text="@string/thursday"
        app:layout_constraintBottom_toTopOf="@+id/fri"
        app:layout_constraintStart_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintTop_toBottomOf="@id/wed" />

    <Button
        android:id="@+id/fri"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:text="@string/friday"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline_dayselection"
        app:layout_constraintTop_toBottomOf="@id/thur" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline_dayselection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="196dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.15339233" />


</android.support.constraint.ConstraintLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You maybe having this error on your java files because there is one or more XML file with error.

Go through all your XML files and resolve errors, then clean or rebuild project from build menu

Start with your most recent edited XML file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...