1

打开几乎没有代码的应用程序时发生崩溃。

代码是:

package com.spotsofmagic.spotsofmagic;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.bluetooth.*;

public class CardActivity extends Activity implements OnClickListener {

    private static final String TAG = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card_activity);

    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

    }
}

应用程序立即崩溃。堆栈跟踪如下,这对我来说意义不大:

08-30 22:37:31.698: W/dalvikvm(8852): threadid=1: thread exiting with uncaught exception (group=0x40ceb300)
08-30 22:37:31.718: E/AndroidRuntime(8852): FATAL EXCEPTION: main
08-30 22:37:31.718: E/AndroidRuntime(8852): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spotsofmagic.spotsofmagic/com.spotsofmagic.spotsofmagic.CardActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.os.Looper.loop(Looper.java:137)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at java.lang.reflect.Method.invoke(Method.java:511)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at dalvik.system.NativeStart.main(Native Method)
08-30 22:37:31.718: E/AndroidRuntime(8852): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.Activity.setContentView(Activity.java:1867)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at com.spotsofmagic.spotsofmagic.CardActivity.onCreate(CardActivity.java:23)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.Activity.performCreate(Activity.java:5008)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-30 22:37:31.718: E/AndroidRuntime(8852):     ... 11 more
08-30 22:37:31.718: E/AndroidRuntime(8852): Caused by: java.lang.reflect.InvocationTargetException
08-30 22:37:31.718: E/AndroidRuntime(8852):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-30 22:37:31.718: E/AndroidRuntime(8852):     ... 23 more
08-30 22:37:31.718: E/AndroidRuntime(8852): Caused by: android.content.res.Resources$NotFoundException: File Spots of Magic from drawable resource ID #0x7f040000
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.content.res.Resources.loadDrawable(Resources.java:1935)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.View.<init>(View.java:3336)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.view.ViewGroup.<init>(ViewGroup.java:427)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.widget.FrameLayout.<init>(FrameLayout.java:101)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.widget.FrameLayout.<init>(FrameLayout.java:97)
08-30 22:37:31.718: E/AndroidRuntime(8852):     ... 26 more
08-30 22:37:31.718: E/AndroidRuntime(8852): Caused by: java.io.FileNotFoundException: Spots of Magic
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:407)
08-30 22:37:31.718: E/AndroidRuntime(8852):     at android.content.res.Resources.loadDrawable(Resources.java:1927)
08-30 22:37:31.718: E/AndroidRuntime(8852):     ... 31 more

Card_Activity.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@string/app_name"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="25dp" >

    <ImageView 
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
    />
</FrameLayout>
4

2 回答 2

5

android:background="@string/app_name"这就是问题。

背景应该是这样的颜色或可绘制的。

android:background="@drawable/name of drawable"

或者

 android:background="@color/name of color"
于 2012-08-30T21:51:14.443 回答
4

您正在将字符串设置为背景。

android:background="@string/app_name"

你应该设置一个drawable。

android:background="@drawable/my_icon"

并将您的图像放入res/drawable-...文件夹中

于 2012-08-30T21:51:06.623 回答