Home > Net >  Android resource linking failed (None pre-existing solutions worked)
Android resource linking failed (None pre-existing solutions worked)

Time:10-18

Android resource linking failed

There's no error shown while coding in the XML file but when I debug, it popups an error message saying,"Android resource linking failed". Commenting the horizontal scroll-views makes the error go away but I need to use it. It's a fragment layout app. Please provide a solution asap!

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".ui.home.HomeFragment">

    <LinearLayout
        android:id="@ id/l1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@color/black"
            android:gravity="center"
            android:text="MECHDROID"
            android:textColor="@color/white"
            android:textSize="28sp"
            android:textStyle="bold" />

    </LinearLayout>

    <RelativeLayout
        android:id="@ id/r1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@ id/l1">

        <TextView
            android:id="@ id/services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background=""
            android:gravity="center"
            android:text="Services"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:textStyle="bold" />

        <HorizontalScrollView
            android:id="@ id/hsv_services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@ id/services"
            android:background="@color/silver">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:weightSum="2">

                <androidx.cardview.widget.CardView
                    android:id="@ id/web_dev_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView

                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Website Development" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/web_support_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Website Support" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/android_dev_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Android App Development" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/ios_dev_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="iOS App Development" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/dm_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Digital Marketing" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

            </LinearLayout>

        </HorizontalScrollView>

        <TextView
            android:id="@ id/career"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/hsv_services"
            android:layout_margin="10dp"
            android:gravity="center"
            android:text="Career"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:textStyle="bold" />

        <HorizontalScrollView
            android:id="@ id/hsv_career"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@ id/career"
            android:background="@color/silver">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:weightSum="2">

                <androidx.cardview.widget.CardView
                    android:id="@ id/electrician_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Electrician" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/flutter_dev_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Flutter Developer" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/ai_engineer_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="AI Engineer" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@ id/marketing_manager_btn"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_margin="3dp"
                    app:cardCornerRadius="20dp"
                    app:cardElevation="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="center"
                        android:orientation="vertical">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_marginTop="10dp"
                            android:src="@color/black" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="Marketing Manager" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

            </LinearLayout>

        </HorizontalScrollView>

    </RelativeLayout>

</RelativeLayout>

Java

package com.mechdroid.mechtech.ui.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.mechdroid.mechtech.databinding.FragmentHomeBinding;

public class HomeFragment extends Fragment {

    private FragmentHomeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        HomeViewModel homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);

        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        return root;
    }
}

CodePudding user response:

In your code you have android:background="" you have not given any value for background attribute in your <TextView> whose with android:id="@ id/services" Give some value for background.

   <TextView
        android:id="@ id/services"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background=""     //give value here
        android:gravity="center"
        android:text="Services"
        android:textColor="@color/black"
        android:textSize="18sp"
        android:textStyle="bold" />

Note: Also you can simply your xml code by using <RecyclerView> with adapter and item layout. Make layout file for one item only then use recycler view and adapter. To make recycler view horizontal use these two attributes inside recycler view app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" android:orientation="horizontal". Then create an List of items with their values to pass to adapter and adapter will automatically set them. To handle click events you can use interface. So your xml will be simplified a lot. With this you can easily add as many items as you want with your code without making changes to xml.

CodePudding user response:

You are referencing the TextView services in the hsv_services HorizontalScrollView as @ id/services.

<TextView
            android:id="@ id/services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background=""
            android:gravity="center"
            android:text="Services"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:textStyle="bold" />

        <HorizontalScrollView
            android:id="@ id/hsv_services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@ id/services"
            android:background="@color/silver"> 

You need to remove the when referencing other view IDs as the is used to note that it is a new resource and should be added to the resources file.

<TextView
            android:id="@ id/services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background=""
            android:gravity="center"
            android:text="Services"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:textStyle="bold" />

        <HorizontalScrollView
            android:id="@ id/hsv_services"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/services"
            android:background="@color/silver"> 

More detailed explanation here

  • Related