programing

Android xml 오류 : RelativeLayout (@ id / LinearLayout_acc, @ id / ProgressBar_statusScreen)과 함께 "주어진 이름과 일치하는 리소스를 찾을 수 없음"

nasanasas 2020. 9. 3. 19:33
반응형

Android xml 오류 : RelativeLayout (@ id / LinearLayout_acc, @ id / ProgressBar_statusScreen)과 함께 "주어진 이름과 일치하는 리소스를 찾을 수 없음"


좋아요, 이건 정말 짜증나 기 시작했습니다. 이 오류는 논리적이지 않은 매우 특별한 방식으로 나타납니다.

이 오류와 관련된 다른 질문을 이미 살펴 봤다고 말하면서 시작하겠습니다. Google도 마찬가지입니다. 내가 말할 수있는 한, 사람들 String이 동일한 레이아웃 파일 내에없는 리소스 또는 다른 것을 참조하기 때문에 대부분의 유사한 문제가 발생합니다 . '@ id +'또는 이와 유사한 것으로 '+'를 잘못 배치했습니다.

.xml 파일이있는 레이아웃 .xml 파일에서 문제가 발생합니다 RelativeLayout. 여기에는 일부 텍스트 가 포함 된 TableLayout, 2 LinearLayout, 마지막으로 ProgressBar. 내가 원하는 것은 진행률 표시 줄을 사용하여 상대 레이아웃 android:layout_alignParentBottom="true"과 정렬 한 다음 진행률 표시 줄 위에 두 개의 선형 레이아웃을 정렬하는 것입니다 (진행률 표시 줄 위에 정렬 된 아래쪽 선형 레이아웃, 아래쪽 선형 레이아웃 위에 정렬 된 다른 하나).

그것은 충분히 단순해야하고 작동하는 것처럼 보여야합니다. 즉, 그래픽보기가 원하는 결과를 보여줍니다. 그러나 여기에 문제가 있습니다 . Eclipse는 두 개의 선형 레이아웃에 대한 오류를 제공합니다.

"오류 : 주어진 이름 ( '@ id / LinearLayout_acc'값이있는 'layout_above'에서)과 일치하는 리소스를 찾을 수 없습니다."

진행률 표시 줄을 참조하는 다른 선형 레이아웃에 대해서도 동일한 오류가 발생합니다. 오타가 없는지 세 번 이상 확인했으며 (ID는 packagename.R.java에도 있음) 프로젝트를 여러 번 정리해 보았습니다.

프로젝트를 실행하기 전에는 저장 (및 자동 빌드) 할 때 오류가 발생하지 않습니다. 또 다른 이상한 점은 상단 선형 레이아웃 대신 진행률 표시 줄에서 하단 선형 레이아웃을 참조 할 때 오류가 발생하지 않는다는 것입니다!

내 레이아웃 파일 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_activity" >
        <TableLayout
             ... />

        <LinearLayout
            android:id="@+id/LinearLayout_dist"
            android:layout_above="@id/LinearLayout_acc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp" >

            <TextView
                ... />

            <TextView
                ... />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/LinearLayout_acc"
            android:layout_above="@id/ProgressBar_statusScreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

            <TextView
                ... />

            <TextView
                ... />
        </LinearLayout>

        <ProgressBar
            android:id="@+id/ProgressBar_statusScreen"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="16dp" />

</RelativeLayout>

이 오류의 원인이 무엇인지 모르겠습니다.

답변으로 편집

Shrikant came with the solution of changing the order of appearance in the layout file so that elements reference only other elements already defined when the reference is read.
Also, as others have posted, changing @id/ to @+id/, even in a reference, does remove the error messages. As Marco W. wrote in this thread, the thing is you have to use @+id/ the first time each id is mentioned and then use @id/ afterwards, even though the first time may not be a definition.

I made most of the design and set the referred id's in Eclipse's graphical editor, so code that resulted in an error message was automatically inserted. Maybe this is a bug in Eclipse.


Please check the below code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher" >

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/LinearLayout_dist"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/LinearLayout_acc"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FIRST" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SECOND" />
   </LinearLayout>

   <LinearLayout
    android:id="@+id/LinearLayout_acc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ProgressBar_statusScreen"
    android:layout_centerHorizontal="true" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="THIRD" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FOURTH" />
   </LinearLayout>

   <ProgressBar
    android:id="@+id/ProgressBar_statusScreen"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_margin="16dp" />

 </RelativeLayout>

Also check the following link. It says that android:layout_below="@id/myTextView" won't recognise an element with id "myTextView" if it is written after the element you're using it in.


change

@id/LinearLayout_acc

to

@+id/LinearLayout_acc

Change every id @id to @+id, no matter when it's defining or referencing an id. With this, you won't get

Android xml error: “No resource found that matches the given name” with RelativeLayout (@id/LinearLayout_acc, @id/ProgressBar_statusScreen).


 <LinearLayout
        android:id="@+id/LinearLayout_dist"
        android:layout_above="@+id/LinearLayout_acc" <--- here might be a problem you forgot + sign
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp" >

참고URL : https://stackoverflow.com/questions/11668718/android-xml-error-no-resource-found-that-matches-the-given-name-with-relative

반응형