Android应用程序在牛轧糖的TimePickerDialog,Eclipse项目中崩溃了

时间:2017-02-10 11:26:28

标签: android android-7.0-nougat

当我尝试显示TimePickerDialog应用程序崩溃时,

项目在每个牛轧糖设备的 Eclipse IDE 中开发。

以下是我的代码

public class FragementMailScreen extends Fragment implements OnClickListener {
TimePickerDialog mTimePicker;
Calendar mcurrentTime;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.layout_main_screen);
    mainView = inflater.inflate(R.layout.fragment_mail_screen, container,
            false);
    pref = new AppPreferences(getActivity().getApplicationContext());
    typeface = Typeface.createFromAsset(getActivity().getAssets(),
            getString(R.string.font_name));
    txtTopTitle = (TextView) mainView.findViewById(R.id.txtTopTitle);
    mcurrentTime = Calendar.getInstance();
    getAllComponets();
    return mainView;
}


private void setDriverMode() {
    if (pref.getDriverMode().equals("0")) {
        mainView.findViewById(R.id.mainViewMail).setBackgroundColor(
                getResources().getColor(R.color.day_backcolor));
    } else {
        mainView.findViewById(R.id.mainViewMail).setBackgroundColor(
                getResources().getColor(R.color.night_backcolor));
    }
}

@Override
public void onResume() {
    // registerBroadcast();
    ((MainScreen) getActivity()).mMailFragment = this;

    super.onResume();
}

public boolean isFragmentUIActive() {
    return isAdded() && !isDetached() && !isRemoving();
}

public static boolean m_iAmVisible;

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    m_iAmVisible = isVisibleToUser;
}

ListView listMessage;


private void getAllComponets() {

    listMessage = (ListView) mainView.findViewById(R.id.listMessage);

    if (CommonUtilities.isBeta) {
        ((TextView) (mainView.findViewById(R.id.btnVersion)))
                .setText(getString(R.string.text_beta));
    } else {
        ((TextView) (mainView.findViewById(R.id.btnVersion)))
                .setText(getString(R.string.text_test));
    }
    listMessage.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            CommonCode.gps = new GPSTracker(getActivity());
            if (CommonCode.gps.isGPSEnabled) {
                Messages detail = message.DriverPopupMessageResponse.LstDriverPopupMessageResponse
                        .get(position);
                if (detail.RID == -1) {

                    final int RType;
                    // FLG false means Request Going Home
                    // then RType is 1 else 2
                    if (detail.FLG)
                        RType = 2;
                    else
                        RType = 1;

                    if (RType == 1) {

                        final int c_hour = mcurrentTime
                                .get(Calendar.HOUR_OF_DAY);
                        final int c_minute = mcurrentTime
                                .get(Calendar.MINUTE);


                        mTimePicker = new TimePickerDialogFixedNougatSpinner(getActivity(),R.style.SpinnerTimePicker,
                                new TimePickerDialog.OnTimeSetListener() {
                                    @Override
                                    public void onTimeSet(
                                            TimePicker timePicker,
                                            int selectedHour,
                                            int selectedMinute) {

                                       /* String time = selectedHour + ":"
                                                + selectedMinute;*/
                                        /*new DriverGoingHome_request()
                                                .execute(time, String
                                                        .valueOf(RType));*/
                                    }

                                }, c_hour, c_minute, true)// Yes 24 hour
                                // time
                        {
                            @Override
                            public void onTimeChanged(TimePicker view,
                                                      int hourOfDay, int minute) {


                             /*   if (hourOfDay < c_hour) {
                                    updateTimeDialog(view, c_hour, c_minute);

                                } else if (hourOfDay == c_hour
                                        && minute < c_minute)
                                    updateTimeDialog(view, c_hour, c_minute);*/

                            }

                            private void updateTimeDialog(TimePicker view,
                                                          int c_hour, int c_minute) {
                                // TODO Auto-generated method stub
                                view.setCurrentHour(c_hour);
                                view.setCurrentMinute(c_minute);
                            }
                        };
                        mTimePicker.setTitle("Select Time");
                        mTimePicker.show();

                        // setDividerColor(picker);
                      /*  Button b = mTimePicker
                                .getButton(DialogInterface.BUTTON_POSITIVE);
                        if (b != null) {
                            b.setText("OK");
                        }
                        Button b_Neg = mTimePicker
                                .getButton(DialogInterface.BUTTON_NEGATIVE);
                        if (b_Neg != null) {
                            b_Neg.setText("Cancel");
                        }*/
                       /* Alert_BUTTON_NEGATIVE(mTimePicker);
                        Alert_BUTTON_POSITIVE(mTimePicker);
                    */

                    } else {
                        String time = "";
                        showAlert(
                                time,
                                String.valueOf(RType),
                                getString(R.string.cancel_request_goingHome));
                        // new DriverGoingHome_request().execute(time,
                        // String.valueOf(RType));

                    }
                    // mTimePicker.setOnTimeChangedListener(this);
                }

在上面的代码中,mTimePicker是TimePickerDialog无法正常工作的对象

以下是日志

02-10 16:46:20.758 5234-5249/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
02-10 16:46:21.504 1814-4135/? E/WifiScanningService: Got invalid work source request: WorkSource{} from ClientInfo[uid=10029]
02-10 16:46:21.521 9995-9995/? E/chromium: [ERROR:interface_registry.cc(104)] Failed to locate a binder for interface: autofill::mojom::PasswordManagerDriver
02-10 16:46:21.537 9995-10335/? E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
02-10 16:46:22.480 1814-4340/? E/LocSvc_eng: E/Calling gnss_sv_status_cb
02-10 16:46:24.164 5234-5249/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
02-10 16:46:24.371 9245-9245/? E/InputEventReceiver: Exception dispatching input event.
02-10 16:46:24.371 9245-9245/? E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
02-10 16:46:24.375 9245-9245/? E/MessageQueue-JNI: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class <unknown>
                                                   Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
                                                   Caused by: java.lang.reflect.InvocationTargetException
                                                       at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                       at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                       at android.app.TimePickerDialog.<init>(TimePickerDialog.java:118)
                                                       at com.abbeycaradsproject.test.utill.TimePickerDialogFixedNougatSpinner.<init>(TimePickerDialogFixedNougatSpinner.java:60)
                                                       at com.abbeycaradsproject.test.FragementMailScreen$1$2.<init>(FragementMailScreen.java:169)
                                                       at com.abbeycaradsproject.test.FragementMailScreen$1.onItemClick(FragementMailScreen.java:184)
                                                       at android.widget.AdapterView.performItemClick(AdapterView.java:310)
                                                       at android.widget.AbsListView.performItemClick(AbsListView.java:1155)
                                                       at android.widget.AbsListView$PerformClick.run(AbsListView.java:3152)
                                                       at android.widget.AbsListView.onTouchUp(AbsListView.java:4079)
                                                       at android.widget.AbsListView.onTouchEvent(AbsListView.java:3838)
                                                       at android.view.View.dispatchTouchEvent(View.java:9942)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2344)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                       at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
                                                       at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
                                                       at android.app.Activity.dispatchTouchEvent(Activity.java:3065)
                                                       at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
                                                       at android.view.View.dispatchPointerEvent(View.java:10162)
                                                       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4446)
                                                       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4314)
                                                       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3914)
                                                       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3880)
                                                       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4007)
                                                       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3888)
                                                       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4064)
                                                       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                    at android.view.ViewRootImpl$InputStage.on
02-10 16:46:25.092 9245-9245/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.abbeycaradsproject.test, PID: 9245
                                                 android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class <unknown>
                                                 Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
                                                 Caused by: java.lang.reflect.InvocationTargetException
                                                     at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                     at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                     at android.app.TimePickerDialog.<init>(TimePickerDialog.java:118)
                                                     at com.abbeycaradsproject.test.utill.TimePickerDialogFixedNougatSpinner.<init>(TimePickerDialogFixedNougatSpinner.java:60)
                                                     at com.abbeycaradsproject.test.FragementMailScreen$1$2.<init>(FragementMailScreen.java:169)
                                                     at com.abbeycaradsproject.test.FragementMailScreen$1.onItemClick(FragementMailScreen.java:184)
                                                     at android.widget.AdapterView.performItemClick(AdapterView.java:310)
                                                     at android.widget.AbsListView.performItemClick(AbsListView.java:1155)
                                                     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3152)
                                                     at android.widget.AbsListView.onTouchUp(AbsListView.java:4079)
                                                     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3838)
                                                     at android.view.View.dispatchTouchEvent(View.java:9942)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2344)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                     at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
                                                     at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
                                                     at android.app.Activity.dispatchTouchEvent(Activity.java:3065)
                                                     at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
                                                     at android.view.View.dispatchPointerEvent(View.java:10162)
                                                     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4446)
                                                     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4314)
                                                     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3914)
                                                     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3880)
                                                     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4007)
                                                     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3888)
                                                     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4064)
02-10 16:46:25.093 9245-9245/? E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3914)
                                                     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3880)
                                                     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3888)
                                                     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                     at android.v

以下是XML文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainViewMail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/topViewMail"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:background="@color/blue" >

    <TextView
        android:id="@+id/txtTopTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_horizontal"
        android:textColor="@color/text_color_sub"
        android:textSize="@dimen/maintext_size" />

    <TextView
        android:id="@+id/btnVersion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="40dp"
        android:background="@color/blue"
        android:text="@string/text_beta"
        android:textColor="@android:color/white"
        android:textSize="@dimen/maintext_size_smaller3"
        android:textStyle="bold" />
</RelativeLayout>
<ListView
    android:id="@+id/listMessage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/topViewMail" >
</ListView>

以下是TimePickerDialogFixedNougatSpinner.java

 */

公共类TimePickerDialogFixedNougatSpinner扩展TimePickerDialog {

public TimePickerDialogFixedNougatSpinner(Context context, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView) {

    super(context, listener, hourOfDay, minute, is24HourView);
    fixSpinner(context, hourOfDay, minute, is24HourView);
}


public TimePickerDialogFixedNougatSpinner(Context context, int themeResId, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView) {

    super(context, themeResId, listener, hourOfDay, minute, is24HourView);
    fixSpinner(context, hourOfDay, minute, is24HourView);
}

private void fixSpinner(Context context, int hourOfDay, int minute, boolean is24HourView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // android:timePickerMode spinner and clock began in Lollipop
        try {
            // Get the theme's android:timePickerMode
            final int MODE_SPINNER = 1;
            Class<?> styleableClass = Class.forName("com.android.internal.R$styleable");
            Field timePickerStyleableField = styleableClass.getField("TimePicker");
            int[] timePickerStyleable = (int[]) timePickerStyleableField.get(null);
            final TypedArray a = context.obtainStyledAttributes(null, timePickerStyleable, android.R.attr.timePickerStyle, 0);
            Field timePickerModeStyleableField = styleableClass.getField("TimePicker_timePickerMode");
            int timePickerModeStyleable = timePickerModeStyleableField.getInt(null);
            final int mode = a.getInt(timePickerModeStyleable, MODE_SPINNER);
            a.recycle();
            if (mode == 2) {
                TimePicker timePicker = (TimePicker) findField(TimePickerDialog.class, TimePicker.class, "mTimePicker").get(this);
                Class<?> delegateClass = Class.forName("android.widget.TimePicker$TimePickerDelegate");
                Field delegateField = findField(TimePicker.class, delegateClass, "mDelegate");
                Object delegate = delegateField.get(timePicker);
                Class<?> spinnerDelegateClass;
                if (Build.VERSION.SDK_INT != Build.VERSION_CODES.LOLLIPOP) {
                    spinnerDelegateClass = Class.forName("android.widget.TimePickerSpinnerDelegate");
                } else {
                    // TimePickerSpinnerDelegate was initially misnamed TimePickerClockDelegate in API 21!
                    spinnerDelegateClass = Class.forName("android.widget.TimePickerClockDelegate");
                }
                // In 7.0 Nougat for some reason the timePickerMode is ignored and the delegate is TimePickerClockDelegate
                if (delegate.getClass() != spinnerDelegateClass) {
                    delegateField.set(timePicker, null); // throw out the TimePickerClockDelegate!
                    timePicker.removeAllViews(); // remove the TimePickerClockDelegate views
                    Constructor spinnerDelegateConstructor = spinnerDelegateClass.getConstructor(TimePicker.class, Context.class, AttributeSet.class, int.class, int.class);
                    spinnerDelegateConstructor.setAccessible(true);
                    // Instantiate a TimePickerSpinnerDelegate
                    delegate = spinnerDelegateConstructor.newInstance(timePicker, context, null, android.R.attr.timePickerStyle, 0);
                    delegateField.set(timePicker, delegate); // set the TimePicker.mDelegate to the spinner delegate
                    // Set up the TimePicker again, with the TimePickerSpinnerDelegate
                    timePicker.setIs24HourView(is24HourView);
                    timePicker.setCurrentHour(hourOfDay);
                    timePicker.setCurrentMinute(minute);
                    timePicker.setOnTimeChangedListener(this);
                }
            }
        } catch (Exception e) {
           // throw new RuntimeException(e);
        }
    }
}

private static Field findField(Class objectClass, Class fieldClass, String expectedName) {
    try {
        Field field = objectClass.getDeclaredField(expectedName);
        field.setAccessible(true);
        return field;
    } catch (NoSuchFieldException e) {} // ignore
    // search for it if it wasn't found under the expected ivar name
    for (Field searchField : objectClass.getDeclaredFields()) {
        if (searchField.getType() == fieldClass) {
            searchField.setAccessible(true);
            return searchField;
        }
    }
    return null;
}

}

0 个答案:

没有答案