2

私は自分のアプリケーションでSwipeRefreshLayoutandを問題なく使用しています。WebView

ViewPagerコード内:

@Override
public Object instantiateItem(View collection, int position) {

    currentArticle = newsList.get(position);

    View webViewContainer =  getActivity().getLayoutInflater().inflate(R.layout.view_pager_item, null);

    WebView webview = (WebView) webViewContainer.findViewById(R.id.webview);
    SetSettingForWebView(webview);
    webview.loadUrl(currentArticle.getArticleURL());
    SwipeRefreshLayout swipe = (SwipeRefreshLayout) webViewContainer.findViewById(R.id.swipe_container);
    setSettingForSwipeLayout(swipe);
    ((ViewPager) collection).addView(webViewContainer, 0);

    return webViewContainer;
}

を定義するかどうかに関係なく、エラーが発生しますSwipeRefreshLayout

これがエラーです。ご覧のとおり、私のコードとは関係ありませんが、これを解決する方法がわかりません

ログ:

05-25 21:55:59.804: E/AndroidRuntime(4665): FATAL EXCEPTION: main
05-25 21:55:59.804: E/AndroidRuntime(4665): Process: com.dimrix.test, PID: 4665
05-25 21:55:59.804: E/AndroidRuntime(4665): java.lang.NullPointerException
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.support.v4.widget.SwipeRefreshLayout.startRefresh(SwipeRefreshLayout.java:441)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.support.v4.widget.SwipeRefreshLayout.onTouchEvent(SwipeRefreshLayout.java:399)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.View.dispatchTouchEvent(View.java:7811)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2169)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1613)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.app.Activity.dispatchTouchEvent(Activity.java:2539)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2117)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.View.dispatchPointerEvent(View.java:8005)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4300)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4179)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3844)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3901)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5973)
05-25 21:55:59.804: E/AndroidRuntime(4665):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.ja
4

4 に答える 4

1

の441行目SwipeRefreshLayout.java

    mListener.onRefresh();

あなたはそれを提供しOnRefreshListenerましたか?

于 2014-05-25T19:21:35.727 に答える
0

project- > Properties -> Java Buildpathに移動し、サポートライブラリ V4を追加し、チェック マークがオンになっていることを確認して、注文およびエクスポートタブからライブラリをチェックします。

于 2014-05-25T19:18:57.717 に答える
0

SwipeRefreshLayout ビューをリスナーで設定しましたか?

たとえば、Fragment/Activity が を実装SwipeRefreshLayout.OnRefreshListenerする場合、SwipeRefreshLayout インスタンスを次のように設定する必要があります。

SwipeRefreshLayout layout = (SwipeRefreshLayout)view.findViewById(R.id.swipe);
layout.setOnRefreshListener(this);

これでクラッシュが修正されるはずです:)

于 2014-08-22T11:56:28.093 に答える
0

これはSwipeRefreshLayout、ViewPager の内部、つまり にあるために発生している可能性がありますview_pager_item.xml。そのSwipeRefreshLayoutため、コンテキストを検索すると、ViewPager を含むアクティビティまたはフラグメントが見つかります。

ViewPager を含む Activity または Fragment に を移動してみて、SwipeRefreshLayoutどうなるか見てみましょう。

于 2014-05-28T23:43:46.173 に答える