2012-02-23 2 views
3

(Android StackOverflowError in ViewGroup.resetResolvedTextDirection) 이전에이 오류에 대해 한 가지 질문을했지만 이제는 에뮬레이터에서 오류를 재현하고이 문제가 발생하는 특정 위치를 좁혔습니다.LinearLayout에 ListView를 추가 할 때 ViewGroup.resetResolvedTextDirection의 Android StackOverflowError

내 활동을 시작할 때 내 서버에서 필요한 데이터를 가져와 모든보기를 만드는 AsyncTask이 있습니다. AsyncTask를의 run() 방법 안에서, 나는 사용자 지정보기를 만드는거야 (그리고 활동의 기본보기에 추가 -하지만 지금은 중요하지) :

ListingView listing = new ListingView(MainActivity.this); 

ListingView

를 확장 내 사용자 지정 뷰 클래스이다 LinearLayout 이 사용자 정의 뷰의 생성자에서이 코드가 있습니다

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:id="@+id/LayoutListingTop" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@color/white"> 
    <ImageView android:id="@+id/ImageView01" 
       android:layout_width="170dp" 
       android:layout_height="62dp" 
       android:src="@drawable/ookl_logo" 
       android:layout_gravity="left" 
       android:adjustViewBounds="false" 
       android:scaleType="fitXY"> 
    </ImageView> 

    <TextView android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:layout_marginBottom="5px" 
       android:gravity="center" 
       android:textColor="@color/black" 
       android:text="@string/love_culture" 
       android:id="@+id/TextView01" 
       android:textSize="28dip"> 
    </TextView> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="horizontal" 
        android:id="@+id/ButtonBar" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/buttonbar" 
        android:paddingLeft="10px" 
        android:paddingRight="10px" 
        android:paddingTop="5px" 
        android:paddingBottom="5px"> 

     <Button android:id="@+id/BtnListVenues" 
        android:layout_width="wrap_content" 
        android:layout_height="45dip" 
        android:background="@null" 
        android:text="@string/button_venues" 
        android:drawableTop="@drawable/icon_venues_on" 
        android:textColor="@color/venue_blue" 
        android:layout_marginRight="10px" 
        android:textSize="9dip"> 
     </Button> 

     <Button android:id="@+id/BtnListEvents" 
        android:layout_width="wrap_content" 
        android:layout_height="45dip" 
        android:background="@null" 
        android:text="@string/button_events" 
        android:drawableTop="@drawable/icon_events_off" 
        android:textColor="@color/white" 
        android:layout_marginRight="10px" 
        android:textSize="9dip"> 
     </Button> 

     <Button android:id="@+id/BtnListTrails" 
        android:layout_width="wrap_content" 
        android:layout_height="45dip" 
        android:background="@null" 
        android:text="@string/button_trails" 
        android:drawableTop="@drawable/icon_trails_off" 
        android:textColor="@color/white" 
        android:layout_marginRight="10px" 
        android:textSize="9dip"> 
     </Button> 

     <Button android:id="@+id/BtnListObjects" 
        android:layout_width="wrap_content" 
        android:layout_height="45dip" 
        android:background="@null" 
        android:text="@string/button_objects" 
        android:drawableTop="@drawable/icon_objects_off" 
        android:textColor="@color/white" 
        android:layout_marginRight="10px" 
        android:textSize="9dip"> 
     </Button> 

     <TextView android:id="@+id/TxtLabelDistance" 
        android:layout_width="fill_parent" 
        android:text="@string/label_distance" 
        android:layout_height="wrap_content" 
        android:gravity="right|bottom" 
        android:layout_alignParentBottom="true" 
        android:textColor="@color/white" 
        android:layout_marginTop="-17px" 
        android:textSize="9dip"> 
     </TextView> 
    </LinearLayout> 


</LinearLayout> 
:이 사용자 정의 뷰 클래스에서

public ListingView(Context context) 
{ 
    this.context = context; 
    ... 

    LayoutInflater infl = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View top = infl.inflate(R.layout.listing, this, true); 
    this.addView(top); 
    ... 

    LinearLayout lst = (LinearLayout)this.findViewById(R.id.LayoutListingTop); 
    tblVenues = new ListView(context); 
    tblVenues.setVisibility(VISIBLE); 
    tblVenues.setItemsCanFocus(true); 
    tblVenues.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      if(venueListener != null && venues.size() > 0) { venueListener.selected(venues.get(position)); } 
     } 
    }); 
    LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
    lst.addView(tblVenues, lp); //this line causes the problem 

    ... 
} 

, tblVenues

private ListView tblVenues; 

로 선언 그리고로드되고있는 XML은 이것이다

Ice Cream Sandwich (4.0) 라인의 Android form 1.6에서 완벽하게 작동합니다.

StackOverflowError에서3210 개
lst.addView(tblVenues, lp); 

결과 :

java.lang.StackOverflowError 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131) 
... this line repeats about 200 times or so ... 

로그 캣에 유용한 다른 곳은 어디에도 없습니다. 본질적으로 생성자에서 오류가 발생하기 때문에 전체 ListingView는 기본 활동보기에 아직 추가되지 않습니다.

나는 무엇이 문제 일 수 있는지에 관해 전반적인 상실감이 있습니다. 어떤 도움이라도 대단히 감사하겠습니다.

답변

2

꽤 많은 시간 동안 내 머리를 벽에 치고 여러 가지 다른 접근법을 시도한 후, 이것은 실제로보기의 visibility이 명시 적으로 VISIBLE으로 설정되어 있지만보기에는 표시되는 안드로이드의 버그라고 생각합니다. 자체보기 및보기의 부모는 주보기에 추가되지 않습니다.

전체보기가 주보기에 추가 된 후 XML에 ListView를 추가하고 코드를 setVisibility(View.VISIBLE)으로 이동하여 마침내 해결했습니다. 즉, 부모 계층 구조는 각 하위에서 끝까지 추적 될 수 있습니다.

적어도이 오류가 더 이상 표시되지 않습니다.

4

[오래된 질문,하지만 난 그래서 그들은 다른 사람에게 도움이있어 희망에 내 노트를 추가, 대답 기색이었습니다.]

하기 Aleks - 나는 핵심 문제는 안드로이드 인 동의 버그,하지만 코드에 추적 (나는 비슷한 문제가 최근에 발생) false로 설정 attachToRoot 매개 변수로 팽창하여 문제를 방지 할 수 있다고 생각합니다. 왜냐하면 attacheToRoot == true로 반환 된 뷰가 전달 된 'root'매개 변수이기 때문입니다. 'this'인 경우 현재 뷰의 자식을 추가합니다 (객체를 자식으로 추가하는 경우). 그 자체의). 이것은 안드로이드를 혼동하는 것처럼 보입니다 (실제로 인스턴스 평등을 확인해야합니다).

http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean)

"[반환] 팽창 된 계층 구조의 루트보기 루트가 공급 attachToRoot에 해당하는 경우 , 이것은 루트입니다.. 그렇지 않으면 팽창 된 XML 파일의 루트입니다"

내 변경 사항으로 인해 변경되었습니다.

+0

흥미 롭습니다 ... 예,이 질문은 낡았습니다. 당시 (분명히) 문제를 해결했습니다. 그러나 지금은 같은 문제에 대한 또 다른 보고서, 특히 Samsung Galaxy 4 기기에 대한 보고서를 받았습니다. 이상하게도 안드로이드와 같은 버전의 다른 장치에서는 발생하지 않으므로 삼성 구현시 버그가되어야합니다. 불행하게도 SG4는 나 자신이 없으므로 디버깅하기가 어렵습니다. 나는 당신의 생각을 시험해 볼 것입니다. –

2

동일한 실수를했기 때문에 Android 자체를 디버깅하고 있었고 실제 이유를 발견했습니다. 당신이 볼 수 있듯이

View top = infl.inflate(R.layout.listing, this, true); 
this.addView(top); 

, 당신은 이미 this에 팽창 된 뷰를 추가 부풀려의 두 번째 매개 변수로 this을 통과, 그래서 당신은 this.addView(top)을 수행 할 때, 그것은 하나 더 추가됩니다 : 진짜 문제는이 라인 내에있는 시각. 다음과 같이 두 가지 방법으로 오류를 수정할 수 있습니다. this.addView(top) 줄을 삭제하거나 thisnull으로 바꿉니다. 두 번째 시도하지 않은,하지만 잘 작동합니다, 그리고 아마도 더 나은 솔루션, 인플레이션 후 부모 추가하기 전에보기를 조작하려는 경우 아마도. BigDSK이 충분하다 언급,하지만 난 null을 전달하고 addViewing 그 후, 또는 addView를 생략하는 것이 더 방탄 솔루션 (IMHO) 것을 발견, 그래서 내가 공유하는 것이라고 생각하는 것이

attachToRoot 매개 변수

.

관련 문제