0

I have found a lot of questions related to this, but not still able to over come mine. So I need help to solve it.

I have ViewPager with 2 Fragments and I tried to add ImageView to the second fragment but application crashed with this error. By the way when I just add TextView or Button without ImageView application, ViewPager works fine. How to solve my problem?

Thanks for any help!

fragment_news.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/news_content"
          android:src="@drawable/news_content"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"/>


</RelativeLayout>

NewsFragment.java

public class NewsFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_news, container, false);
    }
}

ERROR:

02-23 15:14:32.877    1233-1233/www.smartavenue.com E/AndroidRuntime﹕ FATAL 

    EXCEPTION: main
        Process: www.smartavenue.com, PID: 1233
        android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
                at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at www.smartavenue.com.fragment.NewsFragment.onCreateView(NewsFragment.java:16)
                at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
                at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
                at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
                at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
                at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
                at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
                at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
                at android.view.View.measure(View.java:16497)
                at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
                at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
                at android.view.View.measure(View.java:16497)
                at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.onMeasure(CustomViewAbove.java:456)
                at android.view.View.measure(View.java:16497)
                at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
                at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
                at android.view.View.measure(View.java:16497)
7
  • 1
    Have you tried to use another image (a smaller) in your ImageView? Commented Feb 23, 2015 at 16:23
  • After you comment I tried it and it works with smaller imageview. So what max size of ImageView can be for your thinking? Commented Feb 23, 2015 at 16:27
  • I would say that it depends of memory allocated to your application (about 16MB by default I think but I'm not sure). But this error message isn't really explicit. Commented Feb 23, 2015 at 16:35
  • May be that you should load your image in a Bitmap and not directly in your xml file, you'll be able to configure the loading and ensure your image is correctly loaded. developer.android.com/training/displaying-bitmaps/… Commented Feb 23, 2015 at 16:44
  • You know the interesting think is that I used more bigger ImageView in first Fragment but when I set ImageView which is more smaller that first one it didnt work. Really strange. What can you advice to me? Commented Feb 23, 2015 at 16:51

1 Answer 1

2

It is good for me:

In Manifest:

<application
        android:largeHeap="true"

In .xml file, you must remove the below code:

android:src="@drawable..
android:background="@drawable...

Because the error is out of memory error

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.