gpt4 book ai didi

android - 无法启动 Activity ComponentInfo Caused by : android. view.InflateException

转载 作者:行者123 更新时间:2023-11-30 03:07:15 25 4
gpt4 key购买 nike

我的 android 应用程序在打开某些 Activity 时崩溃并出现以下异常:

02-06 10:31:53.608: ERROR/AndroidRuntime(594): FATAL EXCEPTION: main
02-06 10:31:53.608: ERROR/AndroidRuntime(594): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.solaceap/com.example.solaceap.RemoteTV}: android.view.InflateException: Binary XML file line #600: Error inflating class <unknown>
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread.access$600(ActivityThread.java:122)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.os.Looper.loop(Looper.java:137)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread.main(ActivityThread.java:4340)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at java.lang.reflect.Method.invoke(Method.java:511)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at dalvik.system.NativeStart.main(Native Method)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): Caused by: android.view.InflateException: Binary XML file line #600: Error inflating class <unknown>
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.Activity.setContentView(Activity.java:1835)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at com.example.solaceap.RemoteTV.onCreate(RemoteTV.java:84)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.Activity.performCreate(Activity.java:4465)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): ... 11 more
02-06 10:31:53.608: ERROR/AndroidRuntime(594): Caused by: java.lang.reflect.InvocationTargetException
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at java.lang.reflect.Constructor.constructNative(Native Method)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): ... 32 more
02-06 10:31:53.608: ERROR/AndroidRuntime(594): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/remote_tv_num_buttons.xml from drawable resource ID #0x7f02017f
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.content.res.Resources.loadDrawable(Resources.java:1925)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.view.View.<init>(View.java:2780)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.widget.TextView.<init>(TextView.java:445)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.widget.Button.<init>(Button.java:108)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.widget.Button.<init>(Button.java:104)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): ... 35 more
02-06 10:31:53.608: ERROR/AndroidRuntime(594): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/remote_tv_number_selected.xml from drawable resource ID #0x7f020180
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.content.res.Resources.loadDrawable(Resources.java:1925)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.content.res.Resources.getDrawable(Resources.java:664)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): at android.content.res.Resources.loadDrawable(Resources.java:1922)
02-06 10:31:53.608: ERROR/AndroidRuntime(594): ... 40 more
02-06 10:31:53.608: ERROR/AndroidRuntime(594): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file

此异常在 onCreate 方法的 setContentView(R.layout.xml_file) 行上抛出,在查看异常日志后我发现该行XML 中的 600 可能是造成这种情况的原因,这是包含 XML 中的行 600 的代码的一部分,这似乎导致了该错误:

          <LinearLayout
android:id="@+id/zone_control"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="7" >
<Button //this is the line 600
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:layout_weight="1"
android:background="@drawable/num_buttons"
android:clickable="false"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:text="1"
android:textColor="@android:color/white" />
<!.. another three Buttons with the same statistics !..>
</LinearLayout>

这是 num_buttons 可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/remote_tv_number_unselected" />
<item
android:drawable="@drawable/remote_tv_number_selected" />
</selector>

这是remote_tv_number_selected:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp"/>

<gradient
android:startColor="#121212"
android:centerColor="#212121"
android:endColor="#353535"
android:angle="30"/>

</shape>

只是一些翻转的颜色和另一个角度会给你 remote_tv_number_unselected

最佳答案

错误出现在 remote_tv_number_selected 文件的 android:angle 中,因为我将角度设置为 30 但似乎没有除了严格的 (0, 90, 180, 270) 之外,我不接受任何角度,所以我这样改变了它:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp"/>

<gradient
android:startColor="#121212"
android:centerColor="#212121"
android:endColor="#353535"
android:angle="180"/>

</shape>

关于android - 无法启动 Activity ComponentInfo Caused by : android. view.InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21598023/

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