0

I'm trying to inflate layout to custom adapter in getView(...) method but sometimes I get an error in title. I already tried to search in similar questions here but I didn't find a solution which worked for me. This error is strange because it occurs just sometimes and only on some devices - complete log is bellow

android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:606)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at cz.anywhere.sochi.adapter.NewsAdapter.getView(NewsAdapter.java:35)
            at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
            at android.widget.AbsListView.obtainView(AbsListView.java:2040)
            at android.widget.ListView.makeAndAddView(ListView.java:1772)
            at android.widget.ListView.fillDown(ListView.java:672)
            at android.widget.ListView.fillSpecific(ListView.java:1330)
            at android.widget.ListView.layoutChildren(ListView.java:1603)
            at android.widget.AbsListView.onLayout(AbsListView.java:1870)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1510)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1589)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1510)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:690)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1510)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:443)
            at android.view.View.layout(View.java:11418)
            at android.view.ViewGroup.layout(ViewGroup.java:4328)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
            at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.L

Here is a source code from Adapter where I'm trying to inflate item_news.xmllayout.

 @Override
    public View getView(int position, View v, ViewGroup parent) {

        if (v == null) {
            v = getInflater().inflate(R.layout.item_news, null);

            ViewHolder holder = new ViewHolder();
            holder.newsImage = (ImageView) v.findViewById(R.id.news_image);
            holder.title = (TextView) v.findViewById(R.id.news_title);
            holder.date = (TextView) v.findViewById(R.id.news_date);
            holder.progressBar = (ProgressBar) v.findViewById(R.id.news_progress);
            holder.source = (ImageView) v.findViewById(R.id.news_source_logo);

            v.setTag(holder);
        }

        final ViewHolder h = (ViewHolder) v.getTag();

        final News news = getItem(position);

        if(news.getImage() == null){
            //TODO - if image isn't available illustration photo must be shown
            h.progressBar.setVisibility(View.GONE);
        }else{

            Picasso.with(getContext()).load(SochiApp.BASE_URL + news.getImage().getSmall()).into(h.newsImage, new Callback() {
                @Override
                public void onSuccess() {
                    h.progressBar.setVisibility(View.GONE);
                }

                @Override
                public void onError() {
                    SochiLog.e(TAG, SochiApp.BASE_URL + news.getImage().getSmall() + " load image error");
                    h.progressBar.setVisibility(View.GONE);
                }
            });
        }

        h.title.setText(news.getTitle());
        h.date.setText(news.getDate_create());

        String category = news.getCategory();

        h.source.setVisibility(View.GONE);

        if(category.equals(FiltrPreferences.NEWS)){
//            h.source.setImageResource(R.drawable.news_logo);

        }else if(category.equals(FiltrPreferences.EXCLUSIVE)){
            h.source.setImageResource(R.drawable.exclusive_logo);
            h.source.setVisibility(View.VISIBLE);
        }else if(category.equals(FiltrPreferences.LETNA)){
//            h.source.setImageResource(R.drawable.czech_official_logo);
        }

        return v;
    }

    private static class ViewHolder {
        ImageView newsImage;
        ProgressBar progressBar;
        TextView title;
        TextView date;
        ImageView source;
    }

And item_news.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:padding="10dp"
        android:layout_height="130dp">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/news_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/dummy_image" />

            <ProgressBar
                android:id="@+id/news_progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true" />

        </RelativeLayout>


        <RelativeLayout
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="10dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/news_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/newsTitle"
                    android:text="@string/dummy_text" />


                <TextView
                    android:id="@+id/news_date"
                    android:text="@string/dummy_text"
                    android:layout_marginTop="5dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />


            </LinearLayout>

            <ImageView
                android:id="@+id/news_source_logo"
                android:adjustViewBounds="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="5dp"
                android:layout_width="15dp"
                android:src="@drawable/exclusive_logo"
                android:layout_height="wrap_content" />


        </RelativeLayout>


    </LinearLayout>

</RelativeLayout>

The error occurs on @+id/news_image ImageView but it appears unpredictably and only on some devices (on Galaxy S4 with Android 4.3 everything works but on Galaxy S3 Android 4.1.2 application sometimes crash on this error)

Thanks for help.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • There should be an inner "caused by" exception in the logcat - include it in the question. Also your view hierarchy looks suspiciously deep, making the app prone to stack overflow. – laalto Jan 16 '14 at 12:21
  • This is vague, but then could you try replacing getInflater() with the LayoutInflater context .getSystemService code ? – Rat-a-tat-a-tat Ratatouille Jan 16 '14 at 13:11

0 Answers0