简体   繁体   English

PullToRefreshGridView膨胀异常

[英]PullToRefreshGridView Inflate Exception

I am using this library https://github.com/chrisbanes/Android-PullToRefresh for implementing a refreshable grid view and i am getting this error: 我正在使用此库https://github.com/chrisbanes/Android-PullToRefresh来实现可刷新的网格视图,并且出现此错误:

android.view.InflateException: Binary XML file line #8: Error inflating class com.handmark.pulltorefresh.library.PullToRefreshGridView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at com.example.retrievetweets.FragmentPhotos.onCreateView(FragmentPhotos.java:55)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:238)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 24 more
Caused by: java.lang.NullPointerException
at com.handmark.pulltorefresh.library.internal.IndicatorLayout.<init>(IndicatorLayout.java:66)
at com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.addIndicatorViews(PullToRefreshAdapterViewBase.java:355)
at com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.updateUIForMode(PullToRefreshAdapterViewBase.java:328)
at com.handmark.pulltorefresh.library.PullToRefreshBase.init(PullToRefreshBase.java:1142)
at com.handmark.pulltorefresh.library.PullToRefreshBase.<init>(PullToRefreshBase.java:113)
at com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.<init>(PullToRefreshAdapterViewBase.java:74)
at com.handmark.pulltorefresh.library.PullToRefreshGridView.<init>(PullToRefreshGridView.java:35)
... 27 more

Here is the xml: 这是xml:

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

<!-- The PullToRefreshGridView replaces a standard GridView widget. -->
    <com.handmark.pulltorefresh.library.PullToRefreshGridView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_grid"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:numColumns="auto_fit"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="1dp"
        android:columnWidth="80dp" 
        android:stretchMode="columnWidth"
        android:gravity="fill"
        ptr:ptrMode="both"
        ptr:ptrDrawable="@drawable/default_ptr_rotate"
         />
     <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:indeterminateOnly="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />


</RelativeLayout>

And here is the java code for the method onCreateView in FragmentPhotos (the line 55 is this one "ll = (RelativeLayout) inflater.inflate(R.layout.activity_grid_view,"): 这是FragmentPhotos中onCreateView方法的Java代码(第55行是“ ll =(RelativeLayout)inflater.inflate(R.layout.activity_grid_view,“):

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    ref = "";
    fa = getActivity();
    ll = (RelativeLayout) inflater.inflate(R.layout.activity_grid_view,
            container, false);
    bar = (ProgressBar) ll.findViewById(R.id.progressBar);

    mPullRefreshGridView = (PullToRefreshGridView) ll
            .findViewById(R.id.pull_refresh_grid);
    mGridView = mPullRefreshGridView.getRefreshableView();

    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshGridView
            .setOnRefreshListener(new OnRefreshListener<GridView>() {

                @Override
                public void onRefresh(
                        PullToRefreshBase<GridView> refreshView) {
                    // TODO Auto-generated method stub
                    if (NetworkReceiver.mobileConnected) {

                        new GetDataTaskWhitoutLoading().execute();
                    } else {
                        Toast.makeText(
                                getActivity(),
                                "Ahora mismo no se pueden cargar nuevos datos."
                                        + " Comprueba la conexi—n a Internet.",
                                Toast.LENGTH_LONG).show();
                        mPullRefreshGridView.onRefreshComplete();
                    }
                }
            });

    mGridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position,
                long id) {
            // Do something in response to the click
            Intent intent = new Intent(fa, ImageSelected.class);
            intent.putExtra("URL_image", mListItems.get(position)
                    .subSequence(0, mListItems.get(position).length() - 6));
            startActivity(intent);
        }
    });
    mListItems = new ArrayList<String>();
    mAdapter = new FotosItemAdapter(fa, R.layout.image_group, mListItems);
    mGridView.setAdapter(mAdapter);
    if (NetworkReceiver.mobileConnected) {
        GetDataTask.newInstance(bar).execute();
    }
    return ll;
}

Thank you!! 谢谢!!

Are you importing in your classhpath on eclipse? 您要在eclipse上导入classhpath吗? Pull to refhresh is a lib for android,then import like this: project properties> android> add lib. 拉至刷新是android的lib,然后按以下方式导入:项目属性> android>添加lib。

In my case it solved by adding this to my project.properties : 就我而言,它通过将其添加到我的project.properties中来解决:

target=android-19
android.library.reference.1=../library

that library is the name of the handmark library. 该库是手写库的名称。

hope be useful. 希望有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM