Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException preventing PullToRefreshListView from inflating #36

Open
dregre opened this issue Oct 29, 2013 · 0 comments
Open

ClassCastException preventing PullToRefreshListView from inflating #36

dregre opened this issue Oct 29, 2013 · 0 comments

Comments

@dregre
Copy link

dregre commented Oct 29, 2013

I get the following error message when using your library:

10-28 23:39:06.536: E/AndroidRuntime(4486): Caused by: java.lang.ClassCastException: com.actionbarsherlock.internal.widget.ActionBarView$HomeView cannot be cast to android.widget.LinearLayout
10-28 23:39:06.536: E/AndroidRuntime(4486):     at eu.erikw.PullToRefreshListView.init(PullToRefreshListView.java:241)
10-28 23:39:06.536: E/AndroidRuntime(4486):     at eu.erikw.PullToRefreshListView.<init>(PullToRefreshListView.java:113)

How I got the error

I put a PullToRefreshListView in a layout XML called home.xml:

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

    <eu.erikw.PullToRefreshListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

I inflated this XML in a fragment called Home.java, which, in turn, I attached to a SherlockActivity (from the open-source library ActionBarSherlock) called MainActivity.java:

Home.java

public class Home extends Fragment {
    private PullToRefreshListView l;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        // Layout
        View v = inflater.inflate(R.layout.home, container, false); 
        l = (PullToRefreshListView) v.findViewById(R.id.listview);

        //Return
        return v;
    }
}

MainActivity.java

public class MainActivity extends Master {
    // Tabs listener
    private class TabsListener implements ActionBar.TabListener {
        private Fragment fragment;
        private String tag;

        public TabsListener(Fragment fragment, String tag) {
            this.fragment = fragment;
            this.tag = tag; 
        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ft.replace(R.id.fragment_container, fragment, tag);
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(fragment);
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // Setup
        super.onCreate(savedInstanceState);

        // Assignments
        context = getApplicationContext();

        // Layout
        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        setContentView(R.layout.activity_main);

        Fragment fHome;
        if((fHome = getSupportFragmentManager().findFragmentByTag(HOME)) == null) fHome = new Home();

        ActionBar.Tab tab = getSupportActionBar().newTab();
        tab.setIcon(R.drawable.home);
        tab.setContentDescription("Home");
        tab.setTabListener(new TabsListener(
            fHome,
            "hom"
            ));
        getSupportActionBar().addTab(tab, false);
        }
}

Other potentially relevant info

I cloned your GitHub, imported the project into Android, then added it as a library to my own project. I made no modifications to your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant