0

我做了一个简单的android应用程序的开头,它运行良好,但是由于我添加了一个pitcure,我有错误:“应用程序已意外停止,再试一次”。我发现了很多关于这个主题的话题,但我没有成功解决我的问题。这是我自己做的第一个真正的应用程序,我希望你能帮助我。在 logcat 我有:

04-18 14:59:13.926: E/AndroidRuntime(331): FATAL EXCEPTION: main
04-18 14:59:13.926: E/AndroidRuntime(331): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.example.joignabilite/com.example.joignabilite.Identification}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.os.Looper.loop(Looper.java:123)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-18 14:59:13.926: E/AndroidRuntime(331):  at java.lang.reflect.Method.invokeNative(Native Method)
04-18 14:59:13.926: E/AndroidRuntime(331):  at java.lang.reflect.Method.invoke(Method.java:507)
04-18 14:59:13.926: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-18 14:59:13.926: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-18 14:59:13.926: E/AndroidRuntime(331):  at dalvik.system.NativeStart.main(Native Method)
04-18 14:59:13.926: E/AndroidRuntime(331): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
04-18 14:59:13.926: E/AndroidRuntime(331):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-18 14:59:13.926: E/AndroidRuntime(331):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.Activity.setContentView(Activity.java:1657)
04-18 14:59:13.926: E/AndroidRuntime(331):  at com.example.joignabilite.Identification.onCreate(Identification.java:12)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-18 14:59:13.926: E/AndroidRuntime(331):  ... 11 more
04-18 14:59:13.926: E/AndroidRuntime(331): Caused by: java.lang.reflect.InvocationTargetException
04-18 14:59:13.926: E/AndroidRuntime(331):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-18 14:59:13.926: E/AndroidRuntime(331):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
04-18 14:59:13.926: E/AndroidRuntime(331):  ... 21 more
04-18 14:59:13.926: E/AndroidRuntime(331): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060001 a=-1 r=0x7f060001}
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.content.res.Resources.loadDrawable(Resources.java:1681)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.View.<init>(View.java:1951)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.View.<init>(View.java:1899)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.view.ViewGroup.<init>(ViewGroup.java:286)
04-18 14:59:13.926: E/AndroidRuntime(331):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
04-18 14:59:13.926: E/AndroidRuntime(331):  ... 24 more

我的活动:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@style/AppTheme"
android:orientation="horizontal"
tools:context=".Identification" >

<TextView
    android:id="@+id/headerFond"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:background="@drawable/header_band"
    tools:ignore="SelectableText" />

<TextView
    android:id="@+id/headerLogo2"
    android:layout_width="40dp"
    android:layout_height="30dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:background="@drawable/logo2_part2"
    tools:ignore="SelectableText" />

<TextView
    android:id="@+id/headerLogo1"
    android:layout_width="80dp"
    android:layout_height="40dp"
    android:layout_toLeftOf="@id/headerLogo2"
    android:background="@drawable/logo2_part1"
    tools:ignore="SelectableText" />

</RelativeLayout>

我的标识.java:

package com.example.joignabilite;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Identification extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_identification);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.identification, menu);
    return true;
}

}

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.joignabilite"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.joignabilite.Identification"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
4

1 回答 1

0

由于以下行,您会收到错误消息:

android:background="@style/AppTheme"

background属性只占用@drawable@color资源。你不能在那里提供样式。

于 2013-04-18T15:33:35.540 回答