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


92

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

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

내가 겪고있는 문제는 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는 참조를 읽을 때 이미 정의 된 다른 요소 만 참조하도록 레이아웃 파일의 모양 순서를 변경하는 솔루션을 제공합니다.
다른 사람이 게시 변화하는 것처럼 또한, @id/@+id/심지어 참조, 오류 메시지를 제거한다. Marco W. 가이 스레드 에서 썼 듯이 , 첫 번째는 정의가 아닐지라도 @+id/각 ID가 언급 @id/될 때 처음 사용하고 나중에 사용해야 한다는 것입니다.

나는 대부분의 디자인을 만들고 Eclipse의 그래픽 편집기에서 참조 된 ID를 설정했기 때문에 오류 메시지가 발생한 코드가 자동으로 삽입되었습니다. 아마도 이것은 Eclipse의 버그 일 것입니다.

답변:


77

아래 코드를 확인하세요

<?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>

또한 다음 링크를 확인하십시오 . android : layout_below = "@ id / myTextView"는 사용중인 요소 뒤에 작성되는 경우 id "myTextView"가있는 요소를 인식하지 못합니다.


8
이 의견을 보내 주셔서 감사합니다. android : layout_below = "@ id / myTextView"는에서 사용중인 요소 뒤에 작성된 경우 ID가 "myTextView"인 요소를 인식하지 못합니다 . "올바른"순서로 요소를 작성해야한다는 것이 우스꽝 스럽지만 문제가 해결되었습니다. 아마도 버그 일 것입니다.
stemadsen

4
확실히 이것은 버그입니다. 레이아웃 ID는 정의 순서와 독립적이어야합니다. 특히 Android Studio의 화면 레이아웃 디자이너가 문제가 없다는 점이 짜증납니다.
dodgy_coder 2015

@stemadsen 버그가 아닙니다. 파서는 단순히 뷰를 만들고 뷰 요소를 처음 만날 때 굴절 (Id)입니다. 방문하지 않은 요소를 참조하고 있습니다. A는 주문 해결할 수있는 문제의 한계를 B와 A. 아래 나중에 B의 정의 자체보다 논리적 문제 자체를 정의하는 시나리오를 고려
마수드 Dadashi

여기서 언급하겠습니다. 작업중인 UI 요소에 대해 작업중인 UI 요소에 대해 작업중인 UI 요소를 참조 할 수 없습니다 (이전이 아님).
ivanleoncz 2011

85

변화

@id/LinearLayout_acc

@+id/LinearLayout_acc

3
와, 실제로 작동합니다. 나는 @id/기존 ID를 참조하고, @+id/새로운 ID를 생성하기위한 것이며, 이들은 교환 될 수 없다고 생각했습니다. 이 접근 방식이 합법적 인 이유는 무엇입니까? 그러면 ID를 두 번 정의합니까?
stemadsen

실제로 id에 대한 긴 값, @ + id /는 긴 값을 나타냅니다. 일부 구성 요소에 일부 ID 값을 할당하면이 ID 만 사용하여 뷰를 참조 할 수 있습니다.
jeet

다른 모든 레이아웃에서 @ + id /가 아닌 @ id /로 다른 ID를 참조하기 때문에 이것은 이상하게 들립니다. 또한 Shrikant가 아래에 언급했듯이 참조 된 요소의 순서를 변경하면 @ id /와 함께 작동합니다.
stemadsen jul.

1
요소를 화면에 표시되는 순서대로 상대 레이아웃에 유지하는 정말 좋은 방법입니다.
GLee

2
알겠습니다! 그 남자에게 메달을 줘. 나중에 레이아웃에서 생성되는 뷰를 참조해야하는 경우이 작업을 수행해야합니다.
Yoraco Gonzales

15

ID @id@+id정의하거나 참조 할 때 모든 ID 를로 변경하십시오 . 이것으로, 당신은 얻을 수 없습니다

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


2
 <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" >
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.