Сбой на FragmentTransaction в onCreate

David Nelson спросил: 14 ноября 2017 в 07:20 в: android

Мое приложение отлично работало во всем, пока не вышла последняя версия Android. Пиксель Google теперь падает с кодом ниже. Я пытаюсь использовать календарное решение Caldroid, и было здорово работать с ним. Однако теперь происходит сбой, когда я пытаюсь заменить фрагмент и выполнить для него .commit().

После прочтения множества статей в стеке об этой проблеме я все еще не вижу что я делаю не так.

Вот мой onCreate:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_schedule);
    context=this;
    initComponents();
    getSharedData();    getAllGameData();    addCaldroidCalendar();
}

И функция addCaldroidCalendar:

public void addCaldroidCalendar() {    caldroidFragment = new CaldroidFragment();    Calendar calendar = Calendar.getInstance();    // setup arguments for calendar view
    Bundle args = new Bundle();
    args.putInt(CaldroidFragment.MONTH, calendar.get(Calendar.MONTH) + 1);
    args.putInt(CaldroidFragment.YEAR, calendar.get(Calendar.YEAR));
    args.putBoolean(CaldroidFragment.SQUARE_TEXT_VIEW_CELL, false);
    caldroidFragment.setArguments(args);    android.support.v4.app.FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.replace(R.id.calendar1, caldroidFragment);
    t.commitNow();

}

А вот и мой пользовательский интерфейс XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:layout_marginBottom="90dp">    <RelativeLayout
        android:id="@+id/rl_main_schedule_screen"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">       <!-- android:layout_above="@+id/rl_calender_view_schedule_screen"-->        <TextView
            android:id="@+id/tv_calender_view_schedule_screen"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Calendar View"
            android:textColor="#000000"
            android:foregroundGravity="center"
            android:textSize="15sp"
            android:gravity="center"
            android:visibility="gone" />        <RelativeLayout
            android:id="@+id/rl_list_view_layout_schedule_screen"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/tv_calender_view_schedule_screen"
            android:layout_above="@+id/rl_calender_view_schedule_screen"
            android:layout_marginBottom="-20dp">
            <TextView
                android:id="@+id/tv_no_data_schedule_screen"
                android:layout_width="fill_parent"
                android:layout_height="30dp"
                android:text="No Data"
                android:textColor="#000000"
                android:foregroundGravity="center"
                android:textSize="12dp"
                android:gravity="center"
                android:visibility="gone" />
            <ListView
                android:id="@+id/lv_all_schedule_screen"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="none"
                android:cacheColorHint="@null"
                android:divider="@null"
                android:layout_marginBottom="30dp" />
        </RelativeLayout>        <RelativeLayout
            android:id="@+id/rl_calender_view_schedule_screen"
            android:layout_width="fill_parent"
            android:layout_height="250dp"
            android:translationY="0dp"
            android:layout_alignParentBottom="true"
            android:background="@null">                <Button
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:text=""
                    android:layout_alignParentTop="true"
                    android:id="@+id/expand_cal_button"
                    android:background="@color/caldroid_transparent"
                    android:layout_marginLeft="70dp"
                    android:layout_marginRight="70dp"/>                <CalendarView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/calendar1"
                    android:layout_gravity="center_vertical" />        </RelativeLayout>    </RelativeLayout></RelativeLayout>

Это приводит к следующему сбою:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.duffek.officiatingUpdate, PID: 31099
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.duffek.officiatingUpdate/com.duffek.officiatingUpdate.TabHomeActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.duffek.officiatingUpdate/com.duffek.officiatingUpdate.ActivitySchedule}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class Button
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                      at android.os.Handler.dispatchMessage(Handler.java:105)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                   Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.duffek.officiatingUpdate/com.duffek.officiatingUpdate.ActivitySchedule}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class Button
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                      at android.app.ActivityThread.startActivityNow(ActivityThread.java:2615)
                      at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)
                      at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)
                      at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:769)
                      at android.widget.TabHost.setCurrentTab(TabHost.java:423)
                      at android.widget.TabHost.addTab(TabHost.java:233)
                      at com.duffek.officiatingUpdate.TabHomeActivity.onCreate(TabHomeActivity.java:40)
                      at android.app.Activity.performCreate(Activity.java:6975)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                      at android.os.Looper.loop(Looper.java:164) 
                      at android.app.ActivityThread.main(ActivityThread.java:6541) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
                   Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class Button
                   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class Button
                   Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
                      at android.content.res.TypedArray.getColorStateList(TypedArray.java:538)
                      at android.widget.TextView.<init>(TextView.java:904)
                      at android.widget.Button.<init>(Button.java:172)
                      at android.widget.Button.<init>(Button.java:147)
                      at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:70)
                      at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                      at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
                      at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
                      at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at com.roomorama.caldroid.CaldroidFragment.onCreateView(CaldroidFragment.java:1257)
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3227)
                      at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                      at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
                      at android.app.Activity.performStart(Activity.java:6992)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
                      at android.app.ActivityThread.startActivityNow(ActivityThread.java:2615)
                      at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)
                      at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)
                      at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:769)
                      at android.widget.TabHost.setCurrentTab(TabHost.java:423)
                      at android.widget.TabHost.addTab(TabHost.java:233)
                      at com.duffek.officiatingUpdate.TabHomeActivity.onCreate(TabHomeActivity.java:40)
                      at android.app.Activity.performCreate(Activity.java:6975)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                      at android.os.Handler.dispatchMessage(Handler.java:105)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Если я закомментирую строку в onCreate:

t.commitNow();

Тогда это работает, но, очевидно, мой календарь не отображается

Это проблема с последней версией Android, и до сих пор у нее не было проблем. Что могло измениться и что я могу делать не так? Это меня полностью поставило в тупик.

0 ответов