2016-09-14 79 views
0

我正嘗試在Android Marshmallow上更新我的應用。android.widget.DayPickerView無法在Android棉花糖上訪問

我有一個DialogDatePicker並在它的TimePicker

   <DatePicker 
       android:id="@+id/new_task_date_picker" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:calendarViewShown="false" 
       android:background="@color/gray_overlay" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginRight="@dimen/margin_normal" 
       android:layout_marginEnd="@dimen/margin_normal" 
       android:layout_marginBottom="@dimen/margin_large" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/new_task_hour" 
       android:textColor="@color/dark_gray" 
       android:textSize="@dimen/text_normal" 
       android:layout_marginBottom="@dimen/margin_normal" /> 

      <TimePicker 
       android:id="@+id/new_task_time_picker" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:timePickerMode="spinner" 
       android:background="@color/gray_overlay" /> 

它的工作在Android上5,但是當我測試,進行了機器人6時,我」我得到這個錯誤的設備上m試圖誇大我的對話框:

android.view.InflateException: Binary XML file line #116: Binary XML file line #116: Error inflating class android.widget.DatePicker 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:539) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                   at com.ikomobi.alptis.main.task.NewTaskDialogFragment.onCreateView(NewTaskDialogFragment.java:80) 
                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) 
                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) 
                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) 
                   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517) 
                   at android.os.Handler.handleCallback(Handler.java:739) 
                   at android.os.Handler.dispatchMessage(Handler.java:95) 
                   at android.os.Looper.loop(Looper.java:148) 
                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                   at java.lang.reflect.Method.invoke(Native Method) 
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                   Caused by: android.view.InflateException: Binary XML file line #116: Error inflating class android.widget.DatePicker 
                   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:694) 
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  
                   at com.ikomobi.alptis.main.task.NewTaskDialogFragment.onCreateView(NewTaskDialogFragment.java:80)  
                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)  
                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)  
                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)  
                   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)  
                   at android.os.Handler.handleCallback(Handler.java:739)  
                   at android.os.Handler.dispatchMessage(Handler.java:95)  
                   at android.os.Looper.loop(Looper.java:148)  
                   at android.app.ActivityThread.main(ActivityThread.java:5417)  
                   at java.lang.reflect.Method.invoke(Native Method)  
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
                   Caused by: java.lang.reflect.InvocationTargetException 
                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                   at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)  
                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  
                   at com.ikomobi.alptis.main.task.NewTaskDialogFragment.onCreateView(NewTaskDialogFragment.java:80)  
                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)  
                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)  
                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)  
                   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)  
                   at android.os.Handler.handleCallback(Handler.java:739)  
                   at android.os.Handler.dispatchMessage(Handler.java:95)  
                   at android.os.Looper.loop(Looper.java:148)  
                   at android.app.ActivityThread.main(ActivityThread.java:5417)  
                   at java.lang.reflect.Method.invoke(Native Method)  
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
                   Caused by: android.view.InflateException: Binary XML file line #28: Binary XML file line #27: Error inflating class android.widget.DayPickerView 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:539) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                   at android.widget.DatePickerCalendarDelegate.<init>(DatePickerCalendarDelegate.java:118) 
                   at android.widget.DatePicker.createCalendarUIDelegate(DatePicker.java:160) 
                   at android.widget.DatePicker.<init>(DatePicker.java:140) 
                   at android.widget.DatePicker.<init>(DatePicker.java:126) 
                   at android.widget.DatePicker.<init>(DatePicker.java:122) 
                   at java.lang.reflect.Constructor.newInstance(Native Method)  
                   at android.view.LayoutInflater.createView(LayoutInflater.java:619)  
                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)  
                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  
                   at com.ikomobi.alptis.main.task.NewTaskDialogFragment.onCreateView(NewTaskDialogFragment.java:80)  
                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)  
                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)  
                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)  
                   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)  
                   at android.os.Handler.handleCallback(Handler.java:739)  
                   at android.os.Handler.dispatchMessage(Handler.java:95)  
                   at android.os.Looper.loop(Looper.java:148)  
                   at android.app.ActivityThread.main(ActivityThread.java:5417)  
                   at java.lang.reflect.Method.invoke(Native Method)  
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
                   Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.DayPickerView 
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782) 
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  
                   at android.widget.DatePickerCalendarDelegate.<init>(DatePickerCalendarDelegate.java:118)  
                   at android.widget.DatePicker.createCalendarUIDelegate(DatePicker.java:160)  
                   at android.widget.DatePicker.<init>(DatePicker.java:140)  
                   at android.widget.DatePicker.<init>(DatePicker.java:126)  
                   at android.widget.DatePicker.<init>(DatePicker.java:122)  
                   at java.lang.reflect.Constructor.newInstance(Native Method)  
                   at android.view.LayoutInflater.createView(LayoutInflater.java:619)  
                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)  
                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)  
                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  
                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  
                   at com.ikomobi.alptis.main.task.NewTaskDialogFragment.onCreateView(NewTaskDialogFragment.java:80)  
                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  
                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)  
                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)  
                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)  
                   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)  
                   at android.os.Handler.handleCallback(Handler.java:739)  
                   at android.os.Handler.dispatchMessage(Handler.java:95)  
                   at android.os.Looper.loop(Looper.java:148)  
                   at android.app.ActivityThread.main(ActivityThread.java:5417)  
                   at java.lang.reflect.Method.invoke(Native Method)  
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
                   Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: java.lang.Class<android.widget.DayPickerView> is not access 

和我的應用程序崩潰。

我的應用程序已經授予了所有的自動化,我不明白髮生了什麼,你有什麼想法嗎?

編輯:

它實際上是一個dialogFragment,我應該有精確的吧...

回答

0

嘗試加入這一行:

android:spinnersShown="true" 

這一項後:

android:calendarViewShown="false" 

編輯:這是我的代碼onCreate的對話框:

public class DateTimeDialog extends Dialog implements android.view.View.OnClickListener { 

    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      setContentView(R.layout.datetimedialog); 

這是我的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/fragstyle" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/please_select" 
     android:id="@+id/textViewDlgHead" 
     android:layout_gravity="center_horizontal" 
     style="@style/text" /> 

    <DatePicker 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/datePicker" 
     android:layout_weight="1" 
     android:calendarViewShown="false" 
     android:spinnersShown="true" 
     android:datePickerMode="spinner" /> 

    <TimePicker 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/timePicker" 
     android:layout_gravity="center_horizontal" 
     android:touchscreenBlocksFocus="false" 
     android:timePickerMode="spinner" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:touchscreenBlocksFocus="false"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="OK" 
      android:id="@+id/btnclosedialog" 
      android:layout_weight="1" 
      style="@style/button" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/cancel" 
      android:id="@+id/btncanceldialog" 
      android:layout_weight="1" 
      style="@style/button" /> 
    </LinearLayout> 

</LinearLayout> 
+0

它不起作用,我仍然有錯誤。 –

+0

編輯 - 試試這個 –

+0

它實際上是一個對話框片段,我已經在對話框上請求FEATURE_NO_TITLE –

0

就使用此構造方法:的

public DatePickerDialog(Context context, int themeResId, DatePickerDialog.OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) 

代替:

public DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener listener, int year, int month, int dayOfMonth) 

爲我工作。