0

My app was recently working great on everything until the latest version of Android came out. The Google Pixel is now crashing with the code below. I am trying to use the Caldroid calendar solution and it's been awesome working with it. However, it now crashes when I try and replace the Fragment and do a .commit() on it.

After reading countless articles on stack about this issue I'm still not seeing what I'm doing wrong.

Here is my onCreate:

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

    getAllGameData();

    addCaldroidCalendar();
}

And the addCaldroidCalendar function:

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();

}

And here is my UI 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>

This results in the following crash:

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)

If I comment out the line on onCreate:

t.commitNow();

Then it works but obviously my calendar doesn't show up

This is an issue with the latest version of Android and did not have any issues before now. What could have changed and what could I be doing wrong? This one has me completely stumped.

David Nelson
  • 752
  • 1
  • 10
  • 27

1 Answers1

0

Well, from your Logs you can see that is because it was not able to resolve the color resource in your button at runtime. Just as a test, remove the background attribute in your XML.

Oscar Rene
  • 361
  • 2
  • 6
  • removed it, but not seeing a change. What makes you say it was the background property from the stack trace? – David Nelson Dec 11 '17 at 18:28
  • Make sure to rebuild your project. This is the part in the log that makes me think about that specific property: `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}` – Oscar Rene Dec 11 '17 at 18:31
  • I went though and removed all background properties, did a rebuild, and I'm seeing the same thing. Thanks for the help so far! Oh and I looked into the library to see if there are any other color properties and not seeing any there either. – David Nelson Dec 11 '17 at 18:41
  • Seems like it might be an issue with the Caldroid library or the theme I'm using. Just posting an update in case anyone else sees this. Will post if I figure out what is causing it. – David Nelson Dec 12 '17 at 17:51