2

我一直在努力ListPreference与 HoloEverywhere 合作。我在一个 XML 文件中定义了我的设置。我holo为属性使用了命名空间。与首选项相关的所有内容都使用org.holoeverywhere包中的类,因此问题出在其他地方。

当我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)

我目前正在使用 a ,但是当我尝试直接在usingPreferenceFragment中添加首选项时会发生完全相同的事情。PreferenceActivityaddPreferencesFromResource(int)

列表首选项 (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 回答 2

2

好的。我已经想通了。

事实证明。HoloEverywhere 1.4.0 中有一个错误。该问题已报告并修复: https ://github.com/ChristopheVersieux/HoloEverywhere/issues/203

不幸的是,该修复尚未合并到 HE GitHub 项目的主分支。它静静地坐在开发分支上,很可能等待下一个版本......

因此,如果你和我有同样的问题,那么你应该使用 dev 分支,或者 fork 存储库并选择这个提交到你的 master 分支。

不过,样式未正确应用于对话框的问题仍然存在。

于 2012-12-20T18:02:47.690 回答
0

查看源代码

   private View createViewFromResource(int position, View convertView,
        ViewGroup parent, int resource) {
    View view;
    TextView text;
    if (convertView == null) {
        view = FontLoader.apply(mInflater.inflate(resource, parent, false));
    } else {
        view = convertView;
    }
    try {
        if (mFieldId == 0) {
            text = (TextView) view;
        } else {
            text = (TextView) view.findViewById(mFieldId);
        }
    } catch (ClassCastException e) {
        Log.e("ArrayAdapter",
                "You must supply a resource ID for a TextView");
        throw new IllegalStateException(
                "ArrayAdapter requires the resource ID to be a TextView", e);
    }

    T item = getItem(position);
    if (item instanceof CharSequence) {
        text.setText((CharSequence) item);
    } else {
        text.setText(item.toString());
    }
    return view;
}

看来textView为null,并没有从布局中解决

于 2012-12-20T10:09:52.283 回答