Home > Enterprise >  "failed linking file resources" problem, Combined with a twist of "attribute orientat
"failed linking file resources" problem, Combined with a twist of "attribute orientat

Time:10-12

I've been studying Xamarin for the past few months, decided to create my first app (a pretty simple straightforward calculator app*), I have been struggling with a CS0117 Resource problem although it solved itself after some exploring in stack overflow, when that solved, 2 other problems appeared,

"failed linking file resources." && "attribute orientation(aka com.companyname.calchopefullyfinal:orientation) not found".

I've been searching aswell for quite some time but no solution works for me, so thought I'd create a new ticket.. activity_main.xml file -

 <?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_weight="1">
        <TextView
            android:id="@ id/calc_text_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:textSize="50sp"
            android:text="123" />
    </HorizontalScrollView>
    <android.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        app:orientation="horizontal"
        android:rowCount="4"
        android:columnCount="4">
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_red_light"
            android:text="C"/>
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="%" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="×" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="÷" />
        <Button
            style="@style/calc_button"
            android:text="7" />
        <Button
            style="@style/calc_button"
            android:text="8" />
        <Button
            style="@style/calc_button"
            android:text="9" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="-" />
        <Button
            style="@style/calc_button"
            android:text="4" />
        <Button
            style="@style/calc_button"
            android:text="5" />
        <Button
            style="@style/calc_button"
            android:text="6" />
        <Button
            style="@style/calc_button_func"
            android:layout_rowSpan="2"
            android:layout_height="170dp"
            android:textColor="@android:color/holo_green_light"
            android:text=" " />
        <Button
            style="@style/calc_button"
            android:text="1" />
        <Button
            style="@style/calc_button"
            android:text="2" />
        <Button
            style="@style/calc_button"
            android:text="3" />
        <Button
            style="@style/calc_button"
            android:text=" /-" />
        <Button
            style="@style/calc_button"
            android:text="0" />
        <Button
            style="@style/calc_button"
            android:text="." />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="=" />
    </android.widget.GridLayout>
</LinearLayout>

MainActivity.cs file -

using Android.Widget;
using Android.OS;
using Android.Views;
using CalcHopefullyFinal;

namespace CalculatorAndroidFinal
{
    [Activity(Label = "CalculatorAndroidFinal", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private TextView calculatorText;

        private string[] numbers = new string[2];
        private string @operator;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            calculatorText = FindViewById<TextView>(Resource.Id.calc_text_view);
        }



        [Java.Interop.Export("ButtonClick")]
        public void ButtonClick(View v)
        {
            Button button = (Button)v;
            if ("0123456789.".Contains(button.Text))
                AddDigitOrDecimalPoint(button.Text);
            else if ("÷× -".Contains(button.Text))
                AddOperator(button.Text);
            else if ("=" == button.Text)
                Calculate();
            else
                Erase();
        }

        private void AddDigitOrDecimalPoint(string value)
        {
            int index = @operator == null ? 0 : 1;

            if (value == "." && numbers[index].Contains("."))
                return;

            numbers[index]  = value;

            UpdateCalculatorText();
        }

        private void AddOperator(string value)
        {
            if (numbers[1] != null)
            {
                Calculate(value);
                return;
            }

            @operator = value;

            UpdateCalculatorText();
        }

        private void Calculate(string newOperator = null)
        {
            double? result = null;
            double? first = numbers[0] == null ? null : (double?)double.Parse(numbers[0]);
            double? second = numbers[1] == null ? null : (double?)double.Parse(numbers[1]);

            switch (@operator)
            {
                case "÷":
                    result = first / second;
                    break;
                case "×":
                    result = first * second;
                    break;
                case " ":
                    result = first   second;
                    break;
                case "-":
                    result = first - second;
                    break;
                case "%":
                    result = (second / 100) * first;
                    break;
            }

            if (result != null)
            {
                numbers[0] = result.ToString();
                @operator = newOperator;
                numbers[1] = null;
                UpdateCalculatorText();
            }
        }

        private void Erase()
        {
            numbers[0] = numbers[1] = null;
            @operator = null;
            UpdateCalculatorText();
        }

        private void UpdateCalculatorText() => calculatorText.Text = $"{numbers[0]} {@operator} {numbers[1]}";
    }
}

The styles.xml file if it matters -

<resources>
    <style name="calc_button">
        <item name="android:layout_width">95dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
        <item name="android:backgroundTint">@color/abc_hint_foreground_material_dark</item>
        <item name="android:padding">10px</item>
    </style>
    <style name="calc_button_func">
        <item name="android:layout_width">95dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
    </style>
    <style name="button_calculator_equal">
        <item name="android:layout_width">380dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
    </style>
</resources>

*I have tried to Clean/Rebuild All multiple times.

*Would add something if forgot.

Would very much appreciate any help since I've been sweating over this for some time now..

CodePudding user response:

"failed linking file resources." && "attribute orientation(aka com.companyname.calchopefullyfinal:orientation) not found".

For this problem, try to replace the following code:

app:orientation="horizontal"

with:

android:orientation="horizontal"

"failed processing manifest." && "resource style/AppTheme (aka com.companyname.calchopefullyfinal:style/AppTheme) not found."

For these problems, try to add AppTheme style in file styles.xml

Please refer to the following code:

  <resources> 

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

      <style name="calc_button">
            <item name="android:layout_width">95dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
            <item name="android:backgroundTint">@color/abc_hint_foreground_material_dark</item>
            <item name="android:padding">10px</item>
      </style>
      <style name="calc_button_func">
            <item name="android:layout_width">95dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
      </style>
      <style name="button_calculator_equal">
            <item name="android:layout_width">380dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
      </style>

</resources>
  • Related