Подтвердить что ты не робот

Ошибка анализа XML: дубликаты атрибутов?

У меня проблемы с настройкой фона для моей кнопки. Я попробовал настроить его на

android:background="@drawable/mybutton_background" 

но это вызвало ошибку, сказав, что "String types not allowed" ссылаясь на "@drawable/mybutton_background". Это также вызвало еще одну ошибку, из-за которой я R.java файл R.java и дал мне "R cannot be resolved into a variable error". Я просто отказался от кнопки и удалил фон, но ошибка осталась после ее удаления. Ну, эта ошибка теперь исчезла, и теперь я получаю сообщение, в котором говорится об ошибке, анализируя XML: дубликаты атрибутов для одной строки кода, но после удаления этой строки сообщение об ошибке переходит к другой строке! Как Eclipse не будет обновляться, чтобы понять, что я удалил эту строку кода. Я проверил обновления и очистил мой проект бесчисленное количество раз, но я все еще получаю ту же ошибку. Кто-нибудь знает, что с моим проектом?

Мой журнал ошибок:

activity_main.xml: Paint.setShadowLayer is not supported.
activity_main.xml: Failed to convert @drawable/ into a drawable
activity_main.xml: Failed to convert android:background=" into a drawable

activity_main:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="android:background=&quot;"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:scaleType="fitCenter"
        android:src="@drawable/ball01" />

    <Button
        android:background="@drawable/"
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_marginBottom="17dp"
        android:background="@drawable/mybutton_background"  <----- where I get the error
        android:focusableInTouchMode="true"
        android:text="Enlighten me!"
        android:textColor="#3f0f7f"
        android:textSize="32sp"
        android:textStyle="bold|italic"
        android:typeface="serif"
        android:visibility="visible" />

    <LinearLayout
        android:layout_width="match_parent"0        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:weightSum="1" >

        <View
            android:id="@+id/view1"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0.2" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:gravity="center_horizontal"
            android:shadowColor="@android:color/white"
            android:shadowRadius="10"
            android:textSize="32sp" />

        <View
            android:id="@+id/view2"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0.2" />

    </LinearLayout>

</RelativeLayout>

MainActivity.java:

package com.example.crystalball;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {


    private CrystalBall mCrystalBall = new CrystalBall();
    private TextView mAnswerLabel;
    private Button mGetAnswerButton;
    private ImageView mCrystallBallImage;

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

        mAnswerLabel = (TextView) findViewById(R.id.textView1);
        mGetAnswerButton = (Button) findViewById(R.id.button1);
        mCrystallBallImage = (ImageView) findViewById(R.id.imageView1);

        mGetAnswerButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                String answer = mCrystalBall.getAnAnswer();

                mAnswerLabel.setText(answer);

                animateCrystalBall();
                animateAnswer();
            }
        });
    }

    public void animateCrystalBall() {
        mCrystallBallImage.setImageResource(R.drawable.ball_animation);
        AnimationDrawable ballAnimation = (AnimationDrawable) mCrystallBallImage.getDrawable();
        if (ballAnimation.isRunning()) {
            ballAnimation.stop();
        }
        ballAnimation.start();
    }

    private void animateAnswer() {
        AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
        fadeInAnimation.setDuration(1500);
        fadeInAnimation.setFillAfter(true);

        mAnswerLabel.setAnimation(fadeInAnimation);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

Спасибо за все, что вы можете внести!

4b9b3361

Ответ 1

В моем случае эта ошибка вызвана дублированием атрибутов xmlns внутри макета. Если у вас есть что-то вроде этого:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>
        <variable
            name="person"
            type="com.abc.PersonEntity" />
    </data>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
...

Удалите атрибут xmlns из второго макета:

    <LinearLayout 
...

Ответ 2

От родительского RelativeLayout XMl android:background="android:background=&quot;" или обновите его с помощью drawable или цветом как android:background="#FFFF00"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="android:background=&quot;" <---remove this or update with correct drawable
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

В приведенной ниже Button XML вы добавили атрибут android:background 2 раза... Что вызвало проблему.

<Button
    android:background="@drawable/"  <-----first time
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_marginBottom="17dp"
    android:background="@drawable/mybutton_background"  <-----second time
    android:focusableInTouchMode="true"
    android:text="Enlighten me!"
    android:textColor="#3f0f7f"
    android:textSize="32sp"
    android:textStyle="bold|italic"
    android:typeface="serif"
    android:visibility="visible" />

Теперь удалите первый... ваша проблема будет решена.

Ответ 3

У вас есть задний фон атрибута

        android:background="@drawable/"
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_marginBottom="17dp"
        android:background="@drawable/mybutton_background"  <----- where I get the error

Ответ 4

android:background="android:background=&quot;" <--quot; remove code here

Посмотрите на эту строку в родительском относительном макете. Просто удалите фон здесь. Из-за этой строки это приводит к тому, что типы строк не допускаются.

И вторая проблема в ниже Button XML, вы добавили android:background 2 раза... Что вызывает "Error parsing XML: duplicate attributes for one line of code". Поэтому просто удалите один фон.

введите код сюда

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"'enter code here'
    android:background="android:background=&quot;" <--Remove this line
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:scaleType="fitCenter"
        android:src="@drawable/ball01" />

    <Button
        android:background="@drawable/"<-- Remove this line
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_marginBottom="17dp"
        android:background="@drawable/mybutton_background"  <----- where I get the error
        android:focusableInTouchMode="true"
        android:text="Enlighten me!"
        android:textColor="#3f0f7f"
        android:textSize="32sp"
        android:textStyle="bold|italic"
        android:typeface="serif"
        android:visibility="visible" />

    <LinearLayout
        android:layout_width="match_parent"0 <--remove this 0 from here.       
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:weightSum="1" >

        <View
            android:id="@+id/view1"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0.2" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:gravity="center_horizontal"
            android:shadowColor="@android:color/white"
            android:shadowRadius="10"
            android:textSize="32sp" />

        <View
            android:id="@+id/view2"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0.2" />

    </LinearLayout>

</RelativeLayout>

Ответ 5

В моем случае в одном из манифеста отсутствовали xmlns:android = "http://schemas.android.com/apk/res/android". В встроенном файле манифеста отладки этот атрибут показан дважды. Добавление этого атрибута в каждый манифест (даже пустой) решило проблему.

Ответ 6

В моем случае ошибка произошла из-за 2 идентификаторов   android: id = "@+id/layout" (id)   а также   android: id = "@+id/parent" (идентификатор линейного макета)

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout"
android:background="@color/plain_background">

<LinearLayout
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
</LinearLayout>