参数异常:在活动中,宽度和高度必须大于0

5
当我在平板电脑上运行我的应用程序而不是手机(这是我以前从未尝试过)时,启动某个活动时会得到此堆栈跟踪。我已经查看了该活动的.xml文件,寻找可能在运行时为0的任何内容,并替换了我想到的所有内容(例如?attr/actionBarSize),但它没有改变任何东西。 我最大的问题是: 堆栈跟踪太长了,无法找到异常的起源。 有什么想法可以找到我的错误吗? PS:我不知道该活动中是否有任何位图,这使得情况更加混乱。
java.lang.IllegalArgumentException: width and height must be > 0                                                                        
     at android.graphics.Bitmap.createBitmap(Bitmap.java:933)                                                                           
     at android.graphics.Bitmap.createBitmap(Bitmap.java:912)                                                                         
     at android.graphics.Bitmap.createBitmap(Bitmap.java:879)                                                                       
     at android.graphics.drawable.VectorDrawable$VectorDrawableState.createCachedBitmapIfNeeded(VectorDrawable.java:711) 
     at android.graphics.drawable.VectorDrawable.draw(VectorDrawable.java:278)
     at android.graphics.drawable.DrawableContainer.draw(DrawableContainer.java:76)
     at android.widget.ExpandableListView.dispatchDraw(ExpandableListView.java:460)
     at android.view.View.draw(View.java:16272)
     at android.widget.AbsListView.draw(AbsListView.java:5983)
     at android.view.View.updateDisplayListIfDirty(View.java:15192)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.draw(View.java:16272)
     at android.view.View.updateDisplayListIfDirty(View.java:15192)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1127)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.updateDisplayListIfDirty(View.java:15187)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1369)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.draw(View.java:16272)
     at android.view.View.updateDisplayListIfDirty(View.java:15192)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.updateDisplayListIfDirty(View.java:15187)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.updateDisplayListIfDirty(View.java:15187)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.updateDisplayListIfDirty(View.java:15187)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.updateDisplayListIfDirty(View.java:15187)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.View.draw(View.java:15990)
     at android.view.ViewGroup.drawChild(ViewGroup.java:3708)
     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
     at android.view.View.draw(View.java:16272)
     at android.widget.FrameLayout.draw(FrameLayout.java:592)
     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:3047)
     at android.view.View.updateDisplayListIfDirty(View.java:15192)
     at android.view.View.getDisplayList(View.java:15215)
     at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:307)
     at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:313)
     at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:352)
     at android.view.ViewRootImpl.draw(ViewRootImpl.java:2815)
     at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2638)
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2226)
     at android.view.ViewRootImpl.doTraversal(ViewRootIm

好的,这是我的gradle依赖项,我现在正在使用24支持库,但错误仍然存在...

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    wearApp project(':wear')
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'org.postgresql:postgresql:9.4.1208.jre7'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.android.gms:play-services-identity:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.google.android.support:wearable:1.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-crash:9.4.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:palette-v7:24.2.1'
}

以下是导致应用程序崩溃的活动的 .xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="@color/colorPrimary"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="org.pbdevelopement.cineapp.SpielplanActivity"
    tools:showIn="@layout/app_bar_spielplan">

    <ExpandableListView
        android:id="@+id/spielplan_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/Grey600"
        android:dividerHeight="1dp"
        android:groupIndicator="@drawable/group_selector_icon"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />
</RelativeLayout>

1
你能发布你的布局XML和活动代码吗? - Mobile Developer
@MobileDeveloper已添加了XML,您对Activity代码的哪个部分感兴趣?它有很多内容... - Maverick283
2个回答

5
听起来你可能正在使用支持库?我曾经遇到过同样的错误并将其追溯到23.4.0中的DrawableCompat.wrap()的漏洞,而此漏洞在支持库的早期和后期版本中不存在。 这个漏洞会错误地将可绘制区域设置为0(或负数,如果是插页式可绘制物时)。 我曾看到这在Android 5.1上导致了崩溃。

我没有看到针对此问题的具体问题,但是查看DrawableWrapperDonut / DrawableWrapperGingerbread的代码后,我可以看到该问题在23.4.0左右引入,后来得到修复,因此如果您使用了有缺陷的版本,切换到良好的版本应该可以解决这个问题。


1
谢谢,那可能是原因。不幸的是我不能再拿到那个平板电脑了,但我一定会试试看...现在先收集你的积分吧 ;) - Maverick283
好吧,这不是原因 :/ 检查我的问题编辑以获取依赖项,我现在已经全部更新了(尽管Android Studio认为在我仍然针对和编译23的情况下拥有24版本是个坏主意...这是个问题吗?) - Maverick283
你说得有些对,但这只在棒棒糖上发生,奇巧和棉花糖都能正常工作... - Maverick283
嗯...是的,在我的情况下,这是支持库错误和Lollipop错误的组合。我找出原因的方法是通过检查对setBounds的调用。您也可以尝试在Bitmap.java的该行中设置断点,其中抛出异常(确保选择适用于您正在运行的Android版本的正确SDK,以便断点匹配!),以查看哪个视图触发了异常。这可能有助于您追踪原因。 - Learn OpenGL ES
关于你对23版本的目标/编译的评论,我之前也看到过那个警告,但自从升级到Android Studio 2.2后就再也没见过了。我在其他官方文档中没有找到这个限制的正式记录,而且即使我将目标设置为23,APK似乎也可以正常运行,所以很有意思想知道这是否只是一个错误的警告,或者造成这个问题的原因是什么。 - Learn OpenGL ES

1
也许你已经解决了这个问题,但是对于后来的人来说,这也是有用的。
如果你在Android 5.1上使用 drawable导致异常或崩溃,你应该尝试使用 drawable来代替它,这对我很有效。这个drawable可以正常显示。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接