0

在我尝试添加图片之前,我一直在学习教程,一切都很好。

在我发布代码之前,这是我正在使用的:

eclipse 与 android 附加构建目标:2.2 api 8 avd 目标:2.2 api 8

在教程中,我被告知要在 res 中创建自己的可绘制文件夹,所以我做了并且在文件夹中有 3 个 .png。是的,我尝试使用 drawable-hdpi 文件夹,但仍然收到此错误:

“抱歉应用程序 blah blah 意外停止,请重试。”

这是我的xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayoutVert"
android:layout_width="wrap_content"
android:layout_height="125dp"
android:background="@layout/activity_postage_calculator"
android:gravity="center|left|top"
android:orientation="vertical"
android:paddingTop="5dp"
tools:context=".PostageCalculator" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:text="@string/package_type"
    android:textColor="@android:color/black"
    android:textSize="20sp" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayoutHoriz1"
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:text="@string/letter" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayoutHoriz2"
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:contentDescription="@string/letter"
        android:src="@drawable/letter" />
      </LinearLayout>
  </LinearLayout>

一些logcat的东西:

01-14 23:27:04.174: D/AndroidRuntime(268): Shutting down VM
01-14 23:27:04.205: W/dalvikvm(268): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-14 23:27:04.294: E/AndroidRuntime(268): FATAL EXCEPTION: main
01-14 23:27:04.294: E/AndroidRuntime(268): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.pitt.cs1635.tdo7.prog1/edu.pitt.cs1635.tdo7.prog1.PostageCalculator}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.os.Looper.loop(Looper.java:123)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-14 23:27:04.294: E/AndroidRuntime(268):  at java.lang.reflect.Method.invokeNative(Native Method)
01-14 23:27:04.294: E/AndroidRuntime(268):  at java.lang.reflect.Method.invoke(Method.java:521)
01-14 23:27:04.294: E/AndroidRuntime(268):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-14 23:27:04.294: E/AndroidRuntime(268):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-14 23:27:04.294: E/AndroidRuntime(268):  at dalvik.system.NativeStart.main(Native Method)
01-14 23:27:04.294: E/AndroidRuntime(268): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-14 23:27:04.294: E/AndroidRuntime(268):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-14 23:27:04.294: E/AndroidRuntime(268):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.Activity.setContentView(Activity.java:1647)
01-14 23:27:04.294: E/AndroidRuntime(268):  at edu.pitt.cs1635.tdo7.prog1.PostageCalculator.onCreate(PostageCalculator.java:12)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-14 23:27:04.294: E/AndroidRuntime(268):  ... 11 more
01-14 23:27:04.294: E/AndroidRuntime(268): Caused by: java.lang.reflect.InvocationTargetException
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.widget.LinearLayout.<init>(LinearLayout.java:115)
01-14 23:27:04.294: E/AndroidRuntime(268):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-14 23:27:04.294: E/AndroidRuntime(268):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-14 23:27:04.294: E/AndroidRuntime(268):  ... 21 more
01-14 23:27:04.294: E/AndroidRuntime(268): Caused by: android.content.res.Resources$NotFoundException: File res/layout/activity_postage_calculator.xml from drawable resource ID #0x7f030000
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.content.res.Resources.loadDrawable(Resources.java:1697)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.View.<init>(View.java:1885)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.View.<init>(View.java:1834)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.view.ViewGroup.<init>(ViewGroup.java:285)
01-14 23:27:04.294: E/AndroidRuntime(268):  ... 25 more
01-14 23:27:04.294: E/AndroidRuntime(268): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag LinearLayout
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:784)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
01-14 23:27:04.294: E/AndroidRuntime(268):  at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-14 23:27:04.294: E/AndroidRuntime(268):  ... 29 more

我是新手,所以你们能给我的任何东西都将不胜感激

4

2 回答 2

1

异常状态: 二进制 XML 文件第 1 行:无效的可绘制标签 LinearLayout

您是否将布局文件(您发布的 XML)放在 res/drawable 目录中?如果是这样,请尝试将其移动到 res/layout 目录。

于 2013-01-15T04:39:27.917 回答
0

该错误表示找不到资源。

检查文件名是否与您在 XML 上调用的文件名相同。并确保文件名全部小写。

于 2013-01-15T04:48:03.793 回答