Search code examples
androidlayout-inflaterpull-to-refresh

Pull to refresh on Android crashes on Inflater


I've downloaded pull to refresh widget for android and now I'm trying to make it work. I copied everything from the plugin and plugin example folder into my project, changed the import reference to R in com.markupartist.android.widget.PullToRefreshListView to my project's R file. Worked fine at this point.

Then I have added another layout into res/layout and started to get weird error messages. This layout is not anyhow used in my project, I just put the file in place. Current exception message is: your content must have a listview whose id attribute is 'android.r.id.list' (there is still the listview in pull_to_refresh.xml from the example project with this id, not anyhow changed). Content of my added xml file (named crasher.xml) is:

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

    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- Article title -->
    <TextView
        android:id="@+id/alr_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Article title"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="15dip"
        android:textStyle="bold"/>

</RelativeLayout>

As I change this newly added layout, the exception sometimes varies and is thrown from line 93 of PullToRefreshListView.java, where the inflater is called to inflate the pull_to_refresh_header file. I am almost sure there is a problem with the inflater and somehow conflicting layouts. For a moment I was getting an error on this line saying that I cannot cast RelativeLayout to LinearLayout (I am not aware of doing it anywhere) - now I don`t remember what exactly I did and cannot reproduce it, but it was only in changing views in the added and unused layout crasher.xml.

I do not perfectly understand the inflating process and cannot determine where is the problem, can anyone help me?

thanks in advance.


Solution

  • I have finally found solution to this kind of problem:

    Clean build seems to be the solution. In NetBeans, Run->Clean and Build, in Eclipse there is a similar option I think. It solves various weird problems with generated layout resources, which are obviously not-very-well cached and re-built during development.