本文主要是介绍Caused by: java.lang.NumberFormatException: For input string: “?2130969371“,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Caused by: java.lang.NumberFormatException: For input string: "?2130969371"
题记报错。
上结论:"?2130969371" ,即:”?attr/sudScrollIndicator“, 是因为sudScrollIndicator自定义属性主题未给定值引起。
在AS工程引入setupdesign和setupcompat时,简单写了个主AppCompatActivity,引用了一个被GlifLayout包裹的布局文件。
如下:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.setupdesign.GlifLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center"android:src="@drawable/ic_circle" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:text="@string/sud_next_button_label"/></LinearLayout>
</com.google.android.setupdesign.GlifLayout>
然后运行,发生如下错误。
E/PartnerCustomizedLayout: Attribute sucUsePartnerResource not found in ComponentInfo{com.test.testd/com.test.testd.MainActivity}
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.test.testd, PID: 6163java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.testd/com.test.testd.MainActivity}: android.view.InflateException: Binary XML file line #2 in com.test.testd:layout/activity_main: Binary XML file line #2 in com.test.testd:layout/activity_main: Error inflating class com.google.android.setupdesign.GlifLayoutat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3582)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3739)at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:100)at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)at android.os.Handler.dispatchMessage(Handler.java:106)at android.os.Looper.loopOnce(Looper.java:201)at android.os.Looper.loop(Looper.java:288)at android.app.ActivityThread.main(ActivityThread.java:7765)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:993)Caused by: android.view.InflateException: Binary XML file line #2 in com.test.testd:layout/activity_main: Binary XML file line #2 in com.test.testd:layout/activity_main: Error inflating class com.google.android.setupdesign.GlifLayoutCaused by: android.view.InflateException: Binary XML file line #2 in com.test.testd:layout/activity_main: Error inflating class com.google.android.setupdesign.GlifLayoutCaused by: java.lang.reflect.InvocationTargetExceptionat java.lang.reflect.Constructor.newInstance0(Native Method)at java.lang.reflect.Constructor.newInstance(Constructor.java:343)at android.view.LayoutInflater.createView(LayoutInflater.java:854)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)at android.view.LayoutInflater.inflate(LayoutInflater.java:659)at android.view.LayoutInflater.inflate(LayoutInflater.java:534)at android.view.LayoutInflater.inflate(LayoutInflater.java:481)at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)at com.test.testd.MainActivity.onCreate(MainActivity.java:54)at android.app.Activity.performCreate(Activity.java:7967)at android.app.Activity.performCreate(Activity.java:7947)at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3555)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3739)at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:100)at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)at android.os.Handler.dispatchMessage(Handler.java:106)at android.os.Looper.loopOnce(Looper.java:201)at android.os.Looper.loop(Looper.java:288)at android.app.ActivityThread.main(ActivityThread.java:7765)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:993)Caused by: android.view.InflateException: Binary XML file line #24 in com.test.testd:layout/sud_glif_template: Binary XML file line #32 in com.test.testd:layout/sud_glif_template_content: Error inflating class com.google.android.setupdesign.view.BottomScrollView
E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #32 in com.test.testd:layout/sud_glif_template_content: Error inflating class com.google.android.setupdesign.view.BottomScrollViewCaused by: java.lang.reflect.InvocationTargetExceptionat java.lang.reflect.Constructor.newInstance0(Native Method)at java.lang.reflect.Constructor.newInstance(Constructor.java:343)at android.view.LayoutInflater.createView(LayoutInflater.java:854)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1263)at android.view.LayoutInflater.rInflate(LayoutInflater.java:1119)at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)at android.view.LayoutInflater.inflate(LayoutInflater.java:682)at android.view.LayoutInflater.inflate(LayoutInflater.java:534)at com.google.android.setupcompat.internal.TemplateLayout.inflateTemplate(TemplateLayout.java:177)at com.google.android.setupdesign.GlifLayout.onInflateTemplate(GlifLayout.java:198)at com.google.android.setupcompat.internal.TemplateLayout.inflateTemplate(TemplateLayout.java:141)at com.google.android.setupcompat.internal.TemplateLayout.init(TemplateLayout.java:83)at com.google.android.setupcompat.internal.TemplateLayout.<init>(TemplateLayout.java:62)at com.google.android.setupcompat.PartnerCustomizationLayout.<init>(PartnerCustomizationLayout.java:75)at com.google.android.setupdesign.GlifLayout.<init>(GlifLayout.java:97)at java.lang.reflect.Constructor.newInstance0(Native Method)at java.lang.reflect.Constructor.newInstance(Constructor.java:343)at android.view.LayoutInflater.createView(LayoutInflater.java:854)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)at android.view.LayoutInflater.inflate(LayoutInflater.java:659)at android.view.LayoutInflater.inflate(LayoutInflater.java:534)at android.view.LayoutInflater.inflate(LayoutInflater.java:481)at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)at com.test.testd.MainActivity.onCreate(MainActivity.java:54)at android.app.Activity.performCreate(Activity.java:7967)at android.app.Activity.performCreate(Activity.java:7947)at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3555)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3739)at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:100)at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)at android.os.Handler.dispatchMessage(Handler.java:106)at android.os.Looper.loopOnce(Looper.java:201)at android.os.Looper.loop(Looper.java:288)at android.app.ActivityThread.main(ActivityThread.java:7765)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:993)Caused by: java.lang.NumberFormatException: For input string: "?2130969371"at java.lang.Integer.parseInt(Integer.java:615)at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:347)at android.content.res.TypedArray.getInt(TypedArray.java:435)at android.view.View.<init>(View.java:5874)at android.view.ViewGroup.<init>(ViewGroup.java:698)
E/AndroidRuntime: at android.widget.FrameLayout.<init>(FrameLayout.java:99)at android.widget.ScrollView.<init>(ScrollView.java:215)at android.widget.ScrollView.<init>(ScrollView.java:211)at android.widget.ScrollView.<init>(ScrollView.java:207)at com.google.android.setupdesign.view.BottomScrollView.<init>(BottomScrollView.java:55)... 46 more
关键性的报错如下(见截图):
根据如上调用栈,一直找到View的5874行,如下代码:
public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {this(context);mSourceLayoutId = Resources.getAttributeSetSourceResId(attrs);final TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, defStyleAttr, defStyleRes);retrieveExplicitStyle(context.getTheme(), attrs);saveAttributeDataForStyleable(context, com.android.internal.R.styleable.View, attrs, a,defStyleAttr, defStyleRes);//......// Set default values.viewFlagValues |= FOCUSABLE_AUTO;viewFlagMasks |= FOCUSABLE_AUTO;final int N = a.getIndexCount();for (int i = 0; i < N; i++) {int attr = a.getIndex(i);switch (attr) {
//......case R.styleable.View_scrollIndicators:final int scrollIndicators =(a.getInt(attr, 0) << SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT) // Line 5874& SCROLL_INDICATORS_PFLAG3_MASK;if (scrollIndicators != 0) {mPrivateFlags3 |= scrollIndicators;initializeScrollIndicators = true;}break;
至此,基本肯定是:R.styleable.View_scrollIndicators的问题。
看布局文件sud_glif_template_content.xml(隶属于引入的Setupdesign公共组件里边定义)。
<!-- Ignore UnusedAttribute: scrollIndicators is new in M. Default to no indicators in olderversions. --><com.google.android.setupdesign.view.BottomScrollViewandroid:id="@+id/sud_scroll_view"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:fillViewport="true"android:scrollIndicators="?attr/sudScrollIndicators"tools:ignore="UnusedAttribute">
在这里给了个符号占位引用,并未直接给出值,值靠给定的Theme主题来定义。
<!-- Values copied from frameworks/base/core/res/res/values/attrs.xml --><attr name="sudScrollIndicators"><!-- No scroll indicators are displayed. --><flag name="none" value="0x00" /><!-- Displays top scroll indicator when view can be scrolled up. --><flag name="top" value="0x01" /><!-- Displays bottom scroll indicator when vew can be scrolled down. --><flag name="bottom" value="0x02" /><!-- Displays left scroll indicator when vew can be scrolled left. --><flag name="left" value="0x04" /><!-- Displays right scroll indicator when vew can be scrolled right. --><flag name="right" value="0x08" /><!-- Displays right scroll indicator when vew can be scrolled in thestart direction. --><flag name="start" value="0x10" /><!-- Displays right scroll indicator when vew can be scrolled in theend direction. --><flag name="end" value="0x20" /></attr>
BottomScrollView是setupdesign里边定义的组件,且其主题在base主题里边有给出值,如果子Theme不重载覆盖,保持默认即可。
总共有4个Theme设置了sudScrollIndicators, 其中一个就是
SudBaseThemeGlif.Light
。
再看自定义且应用到GlifLayout对应的测试activity主题。
发现其实我们并未直接继承自相关主题,而且取了个相同名字的主题,并未完全覆盖自定义的符号应用(例如:?attr/sudScrollIndicators)。
<style name="SudBaseThemeGlif.Light" parent="Theme.AppCompat.Light.NoActionBar"><item name="android:indeterminateTint">?attr/colorControlActivated</item><!-- Specify the indeterminateTintMode to work around a bug in Lollipop --><item name="android:indeterminateTintMode">src_in</item><item name="android:navigationBarColor">@android:color/black</item><item name="android:statusBarColor">@android:color/transparent</item><item name="android:textAppearanceListItemSmall">?attr/textAppearanceListItemSmall</item></style>
至此,
原因水落石出,
1.错误拷贝了setupdesign里边的主题来测试,覆盖了引入子模块的baseTheme设值,且为完全覆盖自定义符号属性值的给定。
2.Caused by: java.lang.NumberFormatException: For input string: "?2130969371" 这句log, 后边的数字就是sudScrollIndicator自定义属性占位符的id, 见如下:
./app/build/generated/not_namespaced_r_class_sources/debug/r/com/google/android/setupdesign/R.java:695: public static final int sudScrollIndicators = 0x7f04031b;
./app/build/intermediates/symbols/debug/R.txt:858:int attr sudScrollIndicators 0x7f04031b
./app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:410: <attr name="sudScrollIndicators">
./app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:3756: <item name="sudScrollIndicators">bottom</item>
./app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:3780: <item name="sudScrollIndicators">bottom</item>
./app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:4097: <item name="sudScrollIndicators">top|bottom</item>
./app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:4116: <item name="sudScrollIndicators">top|bottom</item>
(2130969371的16进制表示即:0x7f04031b, 所以当它找不到值时,?attr/sudScrollIndicator 即解析为:?2130969371)。
这篇关于Caused by: java.lang.NumberFormatException: For input string: “?2130969371“的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!