java.lang.NumberFormatException:无效的int:" res / drawable-hdpi-v4 / ic_action_share.png"

时间:2014-12-09 06:03:43

标签: android numberformatexception android-imagebutton

在操作栏上有一个带有自定义图像的ShareActionProvider按钮。此外,还修改了ShareActionProvider代码(How to hide the share action (which use most) icon near the share action provider?https://gist.github.com/saulpower/10557956)。在几部手机上(三星Galaxy S3 - Android 4.1,华为G730-U10 - Android 4.2)发生了崩溃。

文件ic_action_share.png存在于文件夹drawable-xxhdpi,drawable-xhdpi,drawable-hdpi,drawable-mdpi中。为什么Android从v4文件夹请求此图像(java.lang.NumberFormatException:Invalid int:" res / drawable-xhdpi-v4 / ic_action_share.png")?

堆栈:

android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ImageButton
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.android.internal.app.ActionBarImpl.setCustomView(ActionBarImpl.java:330)
...
Caused by: java.lang.NumberFormatException: Invalid int: "res/drawable-hdpi-v4/ic_action_share.png"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:260)
at android.widget.ImageView.<init>(ImageView.java:151)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at android.widget.ImageButton.<init>(ImageButton.java:83)
java.lang.NumberFormatException: Invalid int: "res/drawable-xhdpi-v4/ic_action_share.png"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.view.View.<init>(View.java:3561)
at android.view.ViewGroup.<init>(ViewGroup.java:432)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ShareActionProvider.onCreateActionView(Unknown Source)
at android.support.v4.view.j.onCreateActionView(Unknown Source)
at android.support.v7.internal.view.menu.y.onCreateActionView(Unknown Source)
at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
at android.support.v7.internal.view.menu.t.getActionView(Unknown Source)
at android.support.v4.view.y.a(Unknown Source)
at com.example.trace.p.a(Unknown Source)
at android.support.v4.app.Fragment.b(Unknown Source)
at android.support.v4.app.n.a(Unknown Source)
at android.support.v4.app.h.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.g.a(Unknown Source)
at android.support.v7.a.m.a(Unknown Source)
at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.n.onCreatePanelMenu(Unknown Source)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:445)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:819)
at android.app.Activity.invalidateOptionsMenu(Activity.java:2690)
...

style.xml

<style name="app_theme" parent="@style/Theme.AppCompat.Light">
    <!-- Support library compatibility -->
    <item name="actionBarWidgetTheme">@style/CustomShareIcon</item>
    ...
    <item name="android:actionBarWidgetTheme" tools:targetApi="14">@style/CustomShareIcon</item>
</style>

<style name="CustomShareIcon" parent="@style/Theme.AppCompat">
    <item name="actionModeShareDrawable">@drawable/ic_action_share</item>
    <item name="*android:actionModeShareDrawable">@drawable/ic_action_share</item>
</style>

1 个答案:

答案 0 :(得分:0)

试试这个

res/drawable-hdpi-v4/文件夹中添加图片 ic_action_share.png

v-4是版本4,因此它只能自动访问v-4文件夹。