java从SDK 21迁移到SDK 28
我完成了这一步,解决了大部分问题,但有一个问题我还没有解决。做了一次搜索,试图理解结果,尝试了一些事情,但仍然没有进展。问题似乎与应用程序中的样式/主题有关
堆栈跟踪
Process: net.myapp.app.debug, PID: 14927
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.myapp.app.debug/net.myapp.app.ui.SplashSreenActivity}: 安卓.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class 安卓.widget.TextView
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at 安卓.app.ActivityThread.-wrap11(Unknown Source:0)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at 安卓.os.Handler.dispatchMessage(Handler.java:105)
at 安卓.os.Looper.loop(Looper.java:164)
at 安卓.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: 安卓.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class 安卓.widget.TextView
Caused by: 安卓.view.InflateException: Binary XML file line #31: Error inflating class 安卓.widget.TextView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at 安卓.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.安卓.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:515)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:423)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.安卓.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:418)
at 安卓.app.Activity.setContentView(Activity.java:2654)
at net.shopayard.app.ui.SplashSreenActivity.onCreate(SplashSreenActivity.java:42)
at 安卓.app.Activity.performCreate(Activity.java:6975)
at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at 安卓.app.ActivityThread.-wrap11(Unknown Source:0)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at 安卓.os.Handler.dispatchMessage(Handler.java:105)
at 安卓.os.Looper.loop(Looper.java:164)
at 安卓.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at 安卓.content.res.TypedArray.getColorStateList(TypedArray.java:538)
at 安卓.widget.TextView.<init>(TextView.java:904)
at 安卓.widget.TextView.<init>(TextView.java:818)
at 安卓.widget.TextView.<init>(TextView.java:814)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at 安卓.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.安卓.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:515)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:423)
at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.安卓.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:418)
at 安卓.app.Activity.setContentView(Activity.java:2654)
at net.myapp.app.ui.SplashSreenActivity.onCreate(SplashSreenActivity.java:42)
at 安卓.app.Activity.performCreate(Activity.java:6975)
at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at 安卓.app.ActivityThread.-wrap11(Unknown Source:0)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at 安卓.os.Handler.dispatchMessage(Handler.java:105)
at 安卓.os.Looper.loop(Looper.java:164)
at 安卓.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:767)
建造。成绩(应用程序)
apply plugin: 'com.安卓.application'
安卓 {
signingConfigs {
debug {
storeFile file('C:/Users/myapp/.安卓/debug.keystore')
}
}
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "net.myapp.app"
minSdkVersion 21
targetSdkVersion 28
versionCode 22
versionName '3.0.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-安卓.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '.debug'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
repositories {
flatDir {
dirs 'libs'
}
}
productFlavors {
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.安卓.support:appcompat-v7:28.0.0'
compile 'com.安卓.support:recyclerview-v7:28.0.0'
compile 'com.安卓.support:cardview-v7:28.0.0'
compile 'com.viewpagerindicator:library:2.4.1'
compile 'com.安卓.support:support-v4:28.0.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:2.3.0'
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-安卓:4.3.5'
compile(name: 'analyticslibrary', ext: 'aar')
compile 'com.google.安卓.gms:play-services-analytics:16.0.4'
}
风格。xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="colorPrimary">@color/primary_color</item>
<item name="colorPrimaryDark">@color/primary_color_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="actionBarSize">@dimen/abc_action_bar_default_height_material</item>
<item name="colorSwitchThumbNormal">@color/switch_thumb_normal</item>
</style>
<style name="ToolbarThemeOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="安卓:subtitleTextStyle">@style/SubTitleTextStyle</item>
<item name="subtitleTextStyle">@style/SubTitleTextStyle</item>
</style>
<style name="SubTitleTextStyle">
<item name="安卓:textStyle">italic</item>
<item name="安卓:textSize">12sp</item>
<item name="安卓:textColor">@color/text_white</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@安卓:color/white</item>
</style>
<style name="SpinnerButton">
<item name="安卓:minHeight">40dp</item>
<item name="安卓:layout_marginLeft">@dimen/content_margin_normal</item>
<item name="安卓:layout_marginRight">@dimen/content_margin_normal</item>
<item name="安卓:background">@drawable/spinner_button_selector</item>
<item name="安卓:textColor">@color/text_black</item>
<item name="安卓:textSize">@dimen/text_size_medium</item>
<item name="安卓:textStyle">italic</item>
</style>
<style name="EditTextRectangleStyle">
<item name="安卓:layout_marginLeft">@dimen/content_margin_normal</item>
<item name="安卓:layout_marginRight">@dimen/content_margin_normal</item>
<item name="安卓:background">@drawable/black_rectangle</item>
<item name="安卓:textColor">@color/text_black</item>
<item name="安卓:textSize">@dimen/text_size_medium</item>
<item name="安卓:textColorHint">@color/text_gray</item>
<item name="安卓:textStyle">italic</item>
</style>
<style name="EditTextStyle">
<item name="安卓:minHeight">40dp</item>
<item name="安卓:layout_marginLeft">@dimen/content_margin_normal</item>
<item name="安卓:layout_marginRight">@dimen/content_margin_normal</item>
<item name="安卓:background">@drawable/edittext_bg</item>
<item name="安卓:textColor">@color/text_black</item>
<item name="安卓:textSize">@dimen/text_size_medium</item>
<item name="安卓:textColorHint">@color/text_gray</item>
<item name="安卓:textStyle">italic</item>
</style>
<style name="EditTextNoMarginsStyle">
<item name="安卓:minHeight">40dp</item>
<item name="安卓:background">@drawable/edittext_bg</item>
<item name="安卓:textColor">@color/text_black</item>
<item name="安卓:textSize">@dimen/text_size_medium</item>
<item name="安卓:textColorHint">@color/text_gray</item>
<item name="安卓:textStyle">italic</item>
</style>
<style name="FormLabelClickable" parent="FormLabelStyle">
<item name="安卓:clickable">true</item>
<item name="安卓:textColor">@color/clickable_black_text</item>
</style>
<style name="FormLabelStyle">
<item name="安卓:minHeight">40dp</item>
<item name="安卓:layout_marginLeft">@dimen/content_margin_normal</item>
<item name="安卓:layout_marginRight">@dimen/content_margin_normal</item>
<item name="安卓:gravity">center_vertical</item>
<item name="安卓:textColor">@color/text_black</item>
<item name="安卓:textSize">@dimen/text_size_medium</item>
<item name="安卓:textStyle">italic</item>
</style>
<style name="StandardSwitch" parent="FormLabelStyle" >
<item name="安卓:padding">1dp</item>
<item name="安卓:textColor">@color/switch_text_dark_gray</item>
</style>
<style name="SwitchLabelStyle">
<item name="安卓:paddingRight">@dimen/content_margin_normal</item>
<item name="安卓:textColor">@color/text_gray</item>
<item name="安卓:textSize">@dimen/text_size_small</item>
</style>
<style name="CustomTabPageIndicator">
<item name="安卓:background">@color/primary_color</item>
<item name="安卓:textSize">12sp</item>
<item name="pstsTextAllCaps">true</item>
<item name="安卓:maxLines">1</item>
<item name="安卓:textColor">#FFAAAAAA</item>
<item name="pstsIndicatorColor">#FFFFFF</item>
<item name="pstsDividerColor">@安卓:color/transparent</item>
<item name="pstsShouldExpand">true</item>
<item name="pstsIndicatorHeight">4dp</item>
<item name="pstsTabPaddingLeftRight">1dp</item>
<item name="pstsUnderlineColor">#FFFFFF</item>
<item name="pstsUnderlineHeight">0dp</item>
</style>
<style name="ButtonBar">
<item name="安卓:paddingLeft">2dp</item>
<item name="安卓:paddingTop">5dp</item>
<item name="安卓:paddingRight">2dp</item>
<item name="安卓:paddingBottom">0dp</item>
<item name="安卓:background">@安卓:drawable/bottom_bar</item>
</style>
<style name="dialog_popup_slideout">
<item name="安卓:windowExitAnimation">@anim/slide_out_dialog</item>
</style>
<style name="dialog_slidein_slideout">
<item name="安卓:windowEnterAnimation">@anim/slide_in_dialog</item>
</style>
<style name="dialog_slidein_left_slideout">
<item name="安卓:windowEnterAnimation">@anim/slide_in_left</item>
<item name="安卓:windowExitAnimation">@anim/slide_out_dialog</item>
</style>
<style name="ButtonBarButton" />
<style name="FullscreenTheme" parent="安卓:Theme.NoTitleBar">
<item name="安卓:windowContentOverlay">@null</item>
<item name="安卓:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
</style>
<style name="FullscreenTheme.NoActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="安卓:windowContentOverlay">@null</item>
<item name="安卓:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
<item name="安卓:windowActionBar">false</item>
<item name="安卓:windowNoTitle">true</item>
<item name="安卓:windowIsFloating">false</item>
</style>
<style name="NumberPickerDialog" parent="DialogCenteredTitle">
<item name="安卓:layout_width">280dp</item>
</style>
<style name="DialogCenteredTitle" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="安卓:windowTitleStyle">@style/CenteredTitle</item>
<item name="colorAccent">@color/accent</item>
<item name="安卓:windowBackground">@安卓:color/transparent</item>
<item name="安卓:windowFrame">@null</item>
<item name="安卓:windowContentOverlay">@null</item>
<item name="安卓:colorBackgroundCacheHint">@null</item>
</style>
<style name="CenteredTitle" parent="Base.TextAppearance.AppCompat.Title">
<item name="安卓:gravity">center</item>
<item name="安卓:layout_width">match_parent</item>
<item name="安卓:layout_gravity">center</item>
<item name="安卓:layout_marginBottom">8dp</item>
</style>
<style name="RedRectangularButton" parent="BlueRectangularButton">
<item name="安卓:background">@drawable/red_rectangle_button_bg_selector</item>
</style>
<style name="BlueRectangularButton">
<item name="安卓:minHeight">40dp</item>
<item name="安卓:paddingLeft">@dimen/rectangular_button_horizontal_margin</item>
<item name="安卓:paddingRight">@dimen/rectangular_button_horizontal_margin</item>
<item name="安卓:textColor">@color/button_text_white</item>
<item name="安卓:background">@drawable/blue_rectangle_button_bg_selector</item>
<item name="安卓:textAllCaps">true</item>
</style>
<style name="ImageViewAttachment">
<item name="安卓:width">0dp</item>
<item name="安卓:minHeight">@dimen/select_image_min_height</item>
<item name="安卓:scaleType">fitCenter</item>
<item name="安卓:background">@drawable/dashed_rectangle_selector</item>
<item name="安卓:layout_weight">0.25</item>
<item name="安卓:src">@drawable/symbol_camera</item>
<item name="安卓:adjustViewBounds">true</item>
</style>
</resources>
活动。xml
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@color/splash_background"
tools:context="net.myapp.app.ui.SplashSreenActivity">
<ImageView
安卓:id="@+id/image"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:src="@drawable/image_menu"
安卓:layout_alignParentBottom="true"
安卓:adjustViewBounds="true"
安卓:scaleType="fitEnd"/>
<ProgressBar
安卓:id="@+id/progressBar"
style="?安卓:attr/progressBarStyleLarge"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_centerInParent="true"
安卓:visibility="gone"/>
<LinearLayout
安卓:id="@+id/layoutError"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_centerInParent="true"
安卓:gravity="center_horizontal"
安卓:paddingBottom="100dp"
安卓:orientation="vertical"
安卓:visibility="gone">
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:padding="16dp"
安卓:textColor="@color/text_black"
安卓:gravity="center_horizontal"
安卓:textSize="16sp"
安卓:text="@string/error_maintenance"/>
<RelativeLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="@dimen/content_margin_normal">
<Button
安卓:id="@+id/buttonRetry"
安卓:layout_width="60dp"
安卓:layout_height="60dp"
安卓:textColor="@color/text_white"
安卓:textSize="12sp"
安卓:text="@string/retry"
安卓:background="@drawable/circle_button_blue_selector"/>
<ProgressBar
安卓:id="@+id/progressBarRetry"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
style="?安卓:attr/progressBarStyleSmall"
安卓:layout_centerInParent="true"
安卓:visibility="invisible"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
弦。xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">myapp</string>
<string name="ic_action_search">Search</string>
<string name="ic_action_profile">Profile</string>
<string name="ic_action_refresh">Refresh</string>
<string name="action_call">Call</string>
<string name="action_email">Email</string>
<string name="action_share">Share</string>
<string name="action_location">Location</string>
<string name="action_report">Report</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="register_below">Register below to receive deals and promotions from local businesses.</string>
<string name="gender">Gender</string>
<string name="birth_year">Year of birth</string>
<string name="island">Island</string>
<string name="button_done">Done</string>
<string name="button_ok">OK</string>
<string name="loading">Loading...</string>
<string name="title_activity_profile">Profile</string>
<string name="title_activity_deals_details">DealsDetailsActivity</string>
<string name="title_activity_fullscreen_image">FullscreenImageActivity</string>
<string name="title_activity_classified_details">ClassifiedDetailsActivity</string>
<string name="title_activity_splash_sreen">SplashSreenActivity</string>
<!-- Splash screen -->
<string name="retry">Retry</string>
<string name="retry_failed">Retry failed</string>
<string name="error_maintenance">The servers are currently undergoing maintenance, please try again in a few minutes.</string>
</resources>
颜色。xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_color_clicked">#0071a8</color>
<color name="primary_color">#004A77</color>
<color name="primary_color_dark">#004368</color>
<color name="switch_thumb_normal">#004A77</color>
<color name="switch_text_dark_gray">#464646</color>
<color name="accent">#80A4BB</color>
<color name="orange">#EA5C04</color>
<color name="dark_red">#A00809</color>
<color name="red_divider">#A91F20</color>
<color name="line_light_gray">#D9D9D9</color>
<color name="text_blue">#004A77</color>
<color name="text_white">#FFFFFF</color>
<color name="text_gray">#969696</color>
<color name="text_content_dark">#333</color>
<color name="text_dark_red">#980000</color>
<color name="tab_text_inactive">#98b6c8</color>
<color name="text_orange">#E74700</color>
<color name="text_black">#111111</color>
<color name="text_black_focused">#888888</color>
<color name="button_blue">#004A77</color>
<color name="button_blue_focused">#0075BA</color>
<color name="menu_list_divider">#9DD0F5</color>
<color name="menu_selected_item_background">#D6EDFF</color>
<color name="black_overlay">#66000000</color>
<color name="search_background">#A7D9FE</color>
<color name="splash_background">#A6D8FD</color>
<color name="darken_filter_color">#22000000</color>
<color name="classified_id_background">#DDDDDD</color>
<color name="red_button">#A00809</color>
<color name="red_button_focused">#f40809</color>
</resources>
这个问题似乎与FullscreenTheme或FullscreenTheme有关。NoActionBar,因为我一直在测试不同的方法,并且在更改这些方法时得到了不同的堆栈跟踪。然而,上面的代码在SDK 21中运行良好。我有一种感觉,训练有素的眼睛会立即看到这个问题,但遗憾的是,我不是一名日常程序员
# 1 楼答案
它明确表示,它未能找到@string/error\u维护。 尝试
clean project
并查看它是否有名为error_maintenance的字符串资源此外,在以前的项目中,我能够创建一个带有点状“error.maintenance”的字符串资源,并使用
@string/error_maintenance
调用它。 从api 28开始,我必须删除字符串中的每个点。xml