Android ListPreference会关闭我的应用程序

时间:2017-03-07 01:09:34

标签: android

你好我们的Android应用程序遇到问题: 我在我的应用程序中添加了一个设置活动,当点击列表首选项时,应用程序停在这里,首选项的XML:    

<PreferenceCategory android:title="Settings">

    <EditTextPreference
        android:selectAllOnFocus="true"
        android:title="Player Name"
        android:key="userName"
        android:defaultValue="default"
        android:summary="Enter Player Name " />
    <ListPreference
        android:key="listPref"
        android:dialogTitle="Choose a a number"
        android:entries="@array/life_list"
        android:entryValues="@array/life_list"
        android:title="Number of attempts" />
</PreferenceCategory>

这里是@ array / life_list:

<?version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="life_list">
    <item>1</item>
    <item>2</item>
    <item>3</item>
</integer-array>

这是调试报告:

D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: binarypet.millionaire, PID: 20571
              java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
                  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
                  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
                  at android.widget.AbsListView.obtainView(AbsListView.java:2828)
                  at android.widget.ListView.measureHeightOfChildren(ListView.java:1290)
                  at android.widget.ListView.onMeasure(ListView.java:1202)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5832)
                  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
                  at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
                  at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5832)
                  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
                  at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
                  at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5832)
                  at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5832)
                  at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5832)
                  at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3012)
                  at android.view.View.measure(View.java:18646)
                  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2310)
                  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1329)
                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1597)
                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1239)
                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:590)
                  at android.view.Choreographer.doFrame(Choreographer.java:560)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:145)
                  at android.app.ActivityThread.main(ActivityThread.java:6145)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
I/Process: Sending signal. PID: 20571 SIG: 9

1 个答案:

答案 0 :(得分:0)

问题在于:

import pandas as pd
from datetime import datetime

class Time(pd.Timestamp):
    def __new__(cls, *args, **kwargs):
        time = pd.Timestamp.__new__(cls, *args, **kwargs)
        time.__class__ = cls
        return time

print type(Time(datetime(2012, 5, 1)))
print type(Time('2012-05-01'))
print type(Time(2012, 5, 1))

我将整数更改为字符串,问题已解决