Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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)
share|improve this question
1  
Have you tried to use another image (a smaller) in your ImageView? – Substitut Feb 23 '15 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? – Nurzhan Nogerbek Feb 23 '15 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. – Substitut Feb 23 '15 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/… – Substitut Feb 23 '15 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? – Nurzhan Nogerbek Feb 23 '15 at 16:51

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.