gpt4 book ai didi

android - 由 NumberFormatException 引起的错误膨胀类 ImageView

转载 作者:行者123 更新时间:2023-11-29 14:24:07 26 4
gpt4 key购买 nike

我最近在 Android 4.2 设备的 ArrayAdaptergetView() 方法中膨胀一个 Spinner 项目时遇到了这个奇怪的错误:

07-27 10:44:18.120 23988-23988/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.xxx.xxx, PID: 23988
android.view.InflateException: Binary XML file line #21: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.view.View.inflate(View.java:17832)
at xxx.xxx.xxx.adapters.SpinnerAdapter.getView(SpinnerAdapter.java:37)
at android.widget.AbsListView.obtainView(AbsListView.java:2338)
at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1605)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1273)
at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1176)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:554)
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1106)
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:980)
at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:962)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: "res/color/tertiary_text_light.xml"
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
at android.content.res.TypedArray.getInt(TypedArray.java:255)
at android.widget.ImageView.<init>(ImageView.java:155)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:1008)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1067)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.view.View.inflate(View.java:17832) 
at xxx.xxx.xxx.adapters.SpinnerAdapter.getView(SpinnerAdapter.java:37) 
at android.widget.AbsListView.obtainView(AbsListView.java:2338) 
at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1605) 
at android.widget.ListView.measureHeightOfChildren(ListView.java:1273) 
at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1176) 
at android.widget.ListPopupWindow.show(ListPopupWindow.java:554) 
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1106) 
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:980) 
at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:962) 
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5299) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
at dalvik.system.NativeStart.main(Native Method)

这是项目布局的 XML:

<!-- item_autocomplete.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="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:gravity="center_vertical"
android:padding="8dp">

<TextView
android:id="@+id/item_autocomplete_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/primaryColor"/>

<ImageView
android:id="@+id/item_autocomplete_img"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_below="@id/item_autocomplete_title"
android:padding="2dp"
android:src="@drawable/ic_location_on_black_18dp"
android:tint="@android:color/tertiary_text_light"/>

<TextView
android:id="@+id/item_autocomplete_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/item_autocomplete_img"
android:layout_toEndOf="@+id/item_autocomplete_img"
android:layout_toRightOf="@+id/item_autocomplete_img"
android:textColor="@android:color/tertiary_text_light"
android:textSize="12sp"/>

</RelativeLayout>

这是崩溃的地方:

    // SpinnerAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = View.inflate(getContext(), RESOURCE, null); <-- Crash
}
...
}

那么,这里出了什么问题? Android Studio 不会向我发出任何警告,并且该应用程序在我测试过的所有设备上都能正常编译和运行...

最佳答案

问题就是android:tint=""是要分配颜色,而不是选择器,@android:color/tertiary_text_light是。

直接使用它的值#808080或通过资源值 en colors.xml会工作 @colors/gray_light .

关于android - 由 NumberFormatException 引起的错误膨胀类 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38610425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com