title: Android - out of memory exception at view creation
body: <p>I'm try to use the MaterialViewPager <a href="https://github.com/florent37/MaterialViewPager" rel="nofollow noreferrer">library</a>.
  Every time i run my application i get the following exception. There is no reference to my own code.</p>
  <blockquote>
  <p>Throwing OutOfMemoryError &quot;Failed to allocate a 6586008 byte
  allocation with 4194304 free bytes and 4MB until OOM&quot;</p>
  <p>Error reporting crash</p>
  <p>at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
  at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:125)
  ....</p>
  </blockquote>
  <p>After debugging i found out that my code stops at the following lines (OverviewPagerFragment - full code see below)</p>
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      Log.d(&quot;Pager&quot;, &quot;onCreateView&quot;);
      View view = inflater.inflate(R.layout.fragment_overview_pager, container, true);
      ButterKnife.bind(this, view);
      return view;
  }
  </code></pre>
  <p>For your help here is my full code of my &quot;OverviewActivity&quot;. The first activity just replace the FrameLayout with &quot;OverviewFragment&quot;. It is pretty the same code as the sample code of the library but i don't know the exception is throwing...</p>
  <pre><code>public class OverviewFragment extends BaseFragment&lt;OverviewView, OverviewPresenter&gt; {
  
      @Bind(R.id.material_view_pager)
      MaterialViewPager materialViewPager;
  
      @Override
      public int getLayoutId() {
          return R.layout.fragment_overview;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          Log.d(&quot;OverviewFragment&quot;, &quot;onActivityCreated&quot;);
          materialViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) {
              @Override
              public Fragment getItem(int position) {
                  Log.d(&quot;OverviewFragment&quot;, &quot;getItem&quot;);
                  return new OverviewPagerFragment();
              }
  
              @Override
              public int getCount() {
                  Log.d(&quot;OverviewFragment&quot;, &quot;getCount&quot;);
                  return 4;
              }
  
              @Override
              public CharSequence getPageTitle(int position) {
                  Log.d(&quot;OverviewFragment&quot;, &quot;getPageTitle&quot;);
                  switch (position % 4) {
                      case 0:
                          return &quot;Eins&quot;;
                      case 1:
                          return &quot;Zwei&quot;;
                      case 2:
                          return &quot;Drei&quot;;
                      case 3:
                          return &quot;Vier&quot;;
                  }
  
                  return &quot;&quot;;
              }
          });
  
          materialViewPager.getViewPager()
                  .setOffscreenPageLimit(materialViewPager.getViewPager().getAdapter().getCount());
          materialViewPager.getPagerTitleStrip().setViewPager(materialViewPager.getViewPager());
      }
  }
  
  
  
  public class OverviewPagerFragment extends Fragment {
  
      RecyclerView.Adapter adapter;
  
      @Bind(R.id.recycler_view)
      RecyclerView recyclerView;
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Log.d(&quot;Pager&quot;, &quot;onCreateView&quot;);
          View view = inflater.inflate(R.layout.fragment_overview_pager, container, true);
          ButterKnife.bind(this, view);
          return view;
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          Log.d(&quot;Pager&quot;, &quot;onViewCreated&quot;);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          recyclerView.setHasFixedSize(true);
  
          adapter = new RecyclerViewMaterialAdapter(new OverviewAdapter());
          recyclerView.setAdapter(adapter);
          MaterialViewPagerHelper.registerRecyclerView(getActivity(), recyclerView, null);
      }
  }
  
  
  public class OverviewAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
      @Override
      public int getItemCount() {
          Log.d(&quot;Adapter&quot;, &quot;getItemCount&quot;);
          return 4;
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          Log.d(&quot;Adapter&quot;, &quot;obCreateViewH&quot;);
          View view = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.overview_item_list, parent, false);
  
          return new RecyclerView.ViewHolder(view){};
      }
  
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  
      }
  }
  </code></pre>
  <p>Can anybody help me? I tried to find my mistake for hours.. Thanks</p>