Ранее я задавал один вопрос об этой ошибке ( Android StackOverflowError в ViewGroup.resetResolvedTextDirection ), однако теперь мне удалось воспроизвести ошибку в эмуляторе и сузил конкретное место, где возникает эта проблема.
Когда я начинаю свою деятельность, у меня есть AsyncTask
, который извлекает необходимые данные с моего сервера и создает все представления.Внутри run()
метода AsyncTask я создаю собственное представление (и добавляю его в основной вид действия - но это сейчас не важно):
ListingView listing = new ListingView(MainActivity.this);
ListingView
- это моепользовательский класс представления, который расширяется от 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;
И загружаемый XMLthis:
<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>
Все это прекрасно работает на Android от 1.6 до 3.x, однако на линии Ice Cream Sandwich (4.0)
lst.addView(tblVenues, lp);
приводит к StackOverflowError
:
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 ...
В LogCat больше нет ничего полезного.Весь ListingView еще даже не добавлен к основному виду активности, потому что ошибка, по сути, выдается из его конструктора.
Я полностью теряюсь в том, в чем может быть проблема.Любая помощь будет принята с благодарностью.