0

我正在使用此库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

这是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>

这是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;
}

谢谢!!

4

2 回答 2

0

您是否在 Eclipse 上的类路径中导入?拉到 refhresh 是 android 的一个库,然后像这样导入:项目属性> android> 添加库。

于 2013-05-12T04:05:40.653 回答
0

就我而言,它通过将其添加到我的project.properties来解决:

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

该库是手印库的名称。

希望有用。

于 2015-07-10T13:39:57.390 回答