ViewPagerを使用して3つのフラグメントをスワイプするTabLayoutセットを使用しています。アプリケーションはタブ間の切り替えを初期化できますが、数回後にクラッシュし、私の第1のフラグメントのonCreateView()メソッドでInflate Exceptionを与えます。ここでエラーコードは次のとおりです。タブビュー間を数回スワイプした後に例外が発生する
06-16 10:38:26.721 8853-8853/com.dietando.gabriel.dietando E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dietando.gabriel.dietando, PID: 8853
android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.dietando.gabriel.dietando.Fragment2.onCreateView(Fragment2.java:34)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1430)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:728)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:608)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:551)
at android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:2008)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1025)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:995)
at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1272)
at android.support.design.widget.TabLayout$TabView.performClick(TabLayout.java:1377)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.dietando.gabriel.dietando.Fragment2.onCreateView(Fragment2.java:34)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1430)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:728)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:608)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:551)
at android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:2008)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1025)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:995)
at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1272)
at android.support.design.widget.TabLayout$TabView.performClick(TabLayout.java:1377)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #9: Duplicate id 0x7f0c0082, tag null, or parent id 0xffffffff with another fragment for com.dietando.gabriel.dietando.FragmentProgressBar
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2293)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.dietando.gabriel.dietando.Fragment2.onCreateView(Fragment2.java:34)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1430)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:728)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:608)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:551)
at android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:2008)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1025)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:995)
at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1272)
at android.support.design.widget.TabLayout$TabView.performClick(TabLayout.java:1377)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
はここでエラーを与えているコードの一部です:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_2, container, false);
}
マイ断片クラスはandroid.support.v4.app.Fragmentを拡張します。 最初にアプリを実行したときではなく、いくつかのスワイプの後にエラーが表示されます。他のフラグメントクラスでも上記と同じメソッドを使用します。ここで
は、私は私のMainActivityにTabLayoutとビューポケットベルを設定しています方法は次のとおりです。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// ViewPager
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
setupViewPager(viewPager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
}
private void setupViewPager(ViewPager viewPager)
{
Fragment2 f2 = new Fragment2();
Fragment1 f1= new Fragment1();
Fragment3 f3 = new Fragment3();
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(f2, "ONE");
adapter.addFragment(f3, "TWO");
adapter.addFragment(f1, "THREE");
viewPager.setAdapter(adapter);
}
そして、ここに私のViewPagerAdapterクラスです:
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<android.support.v4.app.Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager)
{
super(manager);
}
@Override
public android.support.v4.app.Fragment getItem(int position)
{
return mFragmentList.get(position);
}
@Override
public int getCount()
{
return mFragmentList.size();
}
public void addFragment(android.support.v4.app.Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position)
{
return null;
}
}
私は何見当がつかない間違っていて、このエラーについてどこでも見てきましたが、私が見つけたケースは私のものに似ていませんでした。事前に助けてくれてありがとう。 viewPager.setOffscreenPageLimit(2);
これを追加すること
質問を編集し、Javaスタックトレース全体を入力してください。単に "android.view.InflateException:バイナリXMLファイル行#9:エラー"であなたを助けることはできません。 – CommonsWare
申し訳ありませんが、私はすでに質問を編集しました。 –
これはまだJavaスタックトレース全体ではありません。たとえば、行の途中で途切れることがあります。さらに重要なのは、ラップされた例外を表示する1つ以上の「原因」スタンザが存在し、そこに実際の問題が表示されることです。 – CommonsWare