我試圖使用方法setColorSchemeColors
將顏色設置爲SwipeRefreshLayout
,但是如果我嘗試使用它,它總是會拋出NullPointerException,這非常麻煩。SwipeRefreshLayout setColorSchemeColors總是拋出NullPointerException
我的活動代碼看起來像這樣簡單的代碼:
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.content);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setColorSchemeColors(
android.R.color.holo_blue_light,
android.R.color.holo_orange_light,
android.R.color.holo_green_light,
android.R.color.holo_red_light);
我的佈局是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
我試圖設置,即使在的onResume(只想)的顏色和它不工作。
例外:
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.widget.SwipeRefreshLayout.ensureTarget(SwipeRefreshLayout.java:312)
at android.support.v4.widget.SwipeRefreshLayout.setColorSchemeColors(SwipeRefreshLayout.java:292)
at ....
我發現這裏唯一的問題是this,但大家似乎沒有任何問題。
我錯過了什麼嗎?
請發佈完整的堆棧跟蹤。 – 2014-11-06 19:32:52
我發佈了android.support.v4.widget.SwipeRefreshLayout.ensureTarget方法的重要部分 – Proverbio 2014-11-06 19:37:58