#android #android-viewpager #stack-overflow
Вопрос:
Мой проект много раз получает следующую ошибку. Но ошибка не показывает исходный класс.
Это одна из ошибок, которые я получаю:
Fatal Exception: java.lang.StackOverflowError: stack size 8192KB at android.widget.TextView.jumpDrawablesToCurrentState(TextView.java:8240) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:8303) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:8303) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:8303) at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:8303) at android.view.View.onAttachedToWindow(View.java:20750) at android.view.ViewGroup.onAttachedToWindow(ViewGroup.java:5880) at android.view.View.dispatchAttachedToWindow(View.java:21308) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4239) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246) at android.view.View.dispatchAttachedToWindow(View.java:21286) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4239) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246) at android.view.View.dispatchAttachedToWindow(View.java:21286) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4239) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246) at android.view.View.dispatchAttachedToWindow(View.java:21286) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4239) at android.view.ViewGroup.addViewInner(ViewGroup.java:6001) at android.view.ViewGroup.addView(ViewGroup.java:5777)....
Я проверил классы просмотра пейджеров, есть ли что-то не так с этим классом?
public class VPClass extends PagerAdapter { private Context mContext; private LayoutInflater layoutInflater; public VPTutorialClass(Context context) { mContext = context; } @Override public Object instantiateItem(ViewGroup container, final int position) { layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.item_tutorial, container,false); TextView textViewTutorial = view.findViewById(R.id.item_text_view_tutorial); textViewTutorial.setText(mContext.getResources().getString(tutorialMessages[position])); ViewPager vp = (ViewPager) container; vp.addView(view, 0); return view; } ... }
Любая помощь будет оценена по достоинству. Заранее спасибо.
Ответ №1:
Вы забыли добавить a view
к container
этому container.addView(view);
public Object instantiateItem(ViewGroup container, final int position) { View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_tutorial, container, false); TextView textViewTutorial = view.findViewById(R.id.item_text_view_tutorial); ... ... container.addView(view); return view; }