我在Open Beta阶段在Play商店发布了一个Android应用程序。我的一个朋友是从Play商店下载它。但是在启动时,它会抛出org.xmlpull.v1.XmlPullParserException错误。他在Android 4.4上运行它。知道代码有什么问题吗?
这是堆栈跟踪:
android.view.InflateException: Binary XML file line #13: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.aura.androidapp.Browse.GenreAdapter.getView(Browse.java:709)
at com.aura.androidapp.Browse.Browse.setListViewHeightBasedOnChildren(Browse.java:642)
at com.aura.androidapp.Browse.Browse.onCreateView(Browse.java:605)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1638)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1240)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1088)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
at android.view.View.measure(View.java:16834)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:824)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:500)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5378)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5378)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5378)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5378)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5378)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2368)
at android.view.View.measure(View.java:16834)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2246)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1312)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
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:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ripple_effect.xml from drawable resource ID #0x7f0200b1
at android.content.res.Resources.loadDrawable(Resources.java:2152)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3579)
at android.widget.ImageView.<init>(ImageView.java:123)
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.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1013)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1072)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
... 60 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag ripple
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2148)
... 70 more
以下是GenreAdater的getView方法的片段,日志转换指向该片段:
LayoutInflater layoutInflater;
if(convertView == null)
{
layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.genre_list, parent, false); //line number 709
}
这是布局文件genre_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="@+id/linear">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/pop"
android:id="@+id/image"
android:scaleType="fitXY"
android:background="@drawable/ripple_effect"/>
<TextView
android:text="Rock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="30dp"
android:textColor="#f0f0f0"
android:id="@+id/title"
android:background="@android:drawable/screen_background_dark_transparent"
android:textStyle="bold"
android:textAllCaps="true"
android:fontFamily="sans-serif-condensed" />
</FrameLayout>
</LinearLayout>
这是@ drawable / ripple_effect.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#606060"
tools:targetApi="lollipop">
<item
android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#606060" />
</shape>
</item>
</ripple>
值得注意的是,它在开发过程中被曝光的那些设备上工作得很好(即使在从Play商店卸载和重新下载之后)。在新设备上,从Play商店下载后,它会崩溃。
答案 0 :(得分:1)
添加工具时:targetApi =&#34;棒棒糖&#34;对你的XML来说,这应该是你的红旗;-) Android 4.4在Lollipop之前......
在Android API 21中添加了Ripple drawables,您很可能使用新的SDK版本构建应用程序,但无法正确处理兼容性,因此它将在旧版本的Android上运行。
您可以选择设置minSdkVersion =&#34; 21&#34;,但不支持旧版Android。
要支持旧版本,请查看兼容性库,或者最少使用ripple和 drawable / ripple_effect.xml 创建单独的 drawable-v21 / ripple_effect.xml ,而无需涟漪,像这样:
<强>绘制-V21 / ripple_effect.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#606060"
tools:targetApi="lollipop">
<item
android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#606060" />
</shape>
</item>
</ripple>
<强>抽拉/ ripple_effect.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<item xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#606060" />
</shape>
</item>
点击此处了解详情:https://developer.android.com/training/basics/supporting-devices/platforms.html