我的应用程序最近在所有内容上运行良好,直到最新版本的Android出现。谷歌Pixel现在崩溃与下面的代码。我正在尝试使用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();
}
这是我的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>
导致以下崩溃:
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 :(得分:0)
好吧,从日志中你可以看到,因为它无法在运行时解析按钮中的颜色资源。就像测试一样,删除XML中的background属性。