2

I've been struggling to get ListPreference to work with HoloEverywhere. I defined my settings in an XML file. I used the holo namespace for the attributes. Everything that is related to preferences uses classes from the org.holoeverywhere package so the problem lies somewhere else.

The problem occurs when I click on the ListPreference in my app. The preference should open a dialog with options to chose from. Instead it crashes, giving me the following stack trace:

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)

I'm currently using a PreferenceFragment, but the exact same thing happens when I was trying to add the preferences directly in the PreferenceActivity using addPreferencesFromResource(int).

The list preference (XML) itself:

    <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" />

I would also like to add that this happens to all my ListPreference items (i have multiple).

Paul
  • 5,163
  • 3
  • 35
  • 43
  • Ok. I've found out something interesting. This seems to only happen on my emulator (Jar of Beans in my case). I've tested it on two physical devices (4.2 and 4.1) and it works there... Weird... Only thing that is wrong on the physical devices is that the dialog for the preferences completely ignores my app's theme and reverts to stock holo look. – Paul Dec 20 '12 at 10:24
  • Unfortunately it's not only an emulator issue. I've just tried it on a SGSIII running 4.0.4 and the same problem occurs... – Paul Dec 20 '12 at 10:54
  • The only solution that is comming to my mind right now is to implement my own `ListPreference` and i would like to avoid doing that... – Paul Dec 20 '12 at 11:02

2 Answers2

2

OK. I've figured it out.

As it turns out. There is a bug in HoloEverywhere 1.4.0. The issue has already been reported and fixed: https://github.com/ChristopheVersieux/HoloEverywhere/issues/203

Unfortunately the fix has not been merged to the master branch of HE GitHub project. It's sitting calmly on the dev branch most likely waiting for the next release...

So if you have the same problem as me then you should use the dev branch, or fork the repository and cherry-pick THIS commit to your master branch.

The problem with styles not being applied properly to the dialog still persists though.

Paul
  • 5,163
  • 3
  • 35
  • 43
0

Look into source code:

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

It seems that textView is null, and it was not resolved from layout

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
  • I did do that. In fact the TextView is correctly instantiated in this line `view = FontLoader.apply(mInflater.inflate(resource, parent, false));` but later on the comparison `if (mFieldId == 0)` fails and thus `text = (TextView) view.findViewById(mFieldId);` is ran which makes text `null`... – Paul Dec 20 '12 at 10:22
  • But that is as far as I've got... I can't figure out why it's happening... I've rebuild all my projects, cleaned them etc to make sure the `R` files are fresh but that didn't help. – Paul Dec 20 '12 at 10:55
  • Where is your layout for list entries? – Konstantin Pribluda Dec 20 '12 at 14:58
  • It's whatever the default for a ListPreference is. I did not customize it as I've had no need to. – Paul Dec 20 '12 at 14:59