我一直在努力讓ListPreference
與HoloEverywhere合作。 我在XML文件中定義了我的設置。我使用holo
命名空間作爲屬性。與首選項相關的所有內容都使用org.holoeverywhere
包中的類,所以問題在於別的地方。HoloEverywhere + ListPreference =崩潰
當我在我的應用程序中單擊ListPreference
時,會出現該問題。首選項應打開一個對話框,其中包含可供選擇的選項。相反,它崩潰,給我下面的堆棧跟蹤:
12-20 09:42:59.363: E/AndroidRuntime(3005): FATAL EXCEPTION: main
12-20 09:42:59.363: E/AndroidRuntime(3005): java.lang.NullPointerException
12-20 09:42:59.363: E/AndroidRuntime(3005): at org.holoeverywhere.ArrayAdapter.createViewFromResource(ArrayAdapter.java:204)
12-20 09:42:59.363: E/AndroidRuntime(3005): at org.holoeverywhere.ArrayAdapter.getView(ArrayAdapter.java:250)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.AbsListView.obtainView(AbsListView.java:2267)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.ListView.onMeasure(ListView.java:1156)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at org.holoeverywhere.widget.LinearLayout.measureChildWithMargins(LinearLayout.java:233)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at org.holoeverywhere.widget.LinearLayout.measureChildWithMargins(LinearLayout.java:233)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-20 09:42:59.363: E/AndroidRuntime(3005): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.View.measure(View.java:15172)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1075)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.os.Handler.handleCallback(Handler.java:615)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.os.Handler.dispatchMessage(Handler.java:92)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.os.Looper.loop(Looper.java:137)
12-20 09:42:59.363: E/AndroidRuntime(3005): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-20 09:42:59.363: E/AndroidRuntime(3005): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 09:42:59.363: E/AndroidRuntime(3005): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 09:42:59.363: E/AndroidRuntime(3005): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-20 09:42:59.363: E/AndroidRuntime(3005): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-20 09:42:59.363: E/AndroidRuntime(3005): at dalvik.system.NativeStart.main(Native Method)
我目前使用PreferenceFragment
,但同樣的事情發生在我試圖直接使用addPreferencesFromResource(int)
在PreferenceActivity
添加偏好。
名單偏好(XML)本身:
<ListPreference
holo:defaultValue="false"
holo:dialogTitle="@string/sett_inet_access_dial"
holo:entries="@array/sett_inet_access_names"
holo:entryValues="@array/sett_inet_access_values"
holo:key="@string/keysett_inet_access"
holo:summary="@string/sett_inet_access_summ"
holo:title="@string/sett_inet_access_name" />
我還想補充一點,這種情況我所有ListPreference項目(我有多個)。
好的。我發現了一些有趣的東西。這似乎只發生在我的模擬器(在我的情況下,豆類罐)。我已經在兩個物理設備(4.2和4.1)上測試過了,它在那裏工作......怪異的......只有在物理設備上出現錯誤的是,首選項的對話框完全忽略了我的應用程序的主題並恢復爲庫存完整的外觀。 – Paul
不幸的是,它不僅僅是一個模擬器問題。我剛剛在運行4.0.4的SGSIII上嘗試過,發生同樣的問題... – Paul
現在我唯一想到的解決方案是實現我自己的'ListPreference',我想避免這樣做。 .. – Paul