0

谁能向我解释以下 logcat 抱怨什么?

02-08 20:40:04.383: E/AndroidRuntime(10227): FATAL EXCEPTION: main
02-08 20:40:04.383: E/AndroidRuntime(10227): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.decko/com.example.decko.Game}: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.ImageButton
02-08 20:40:04.383: E/AndroidRuntime(10227):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
02-08 20:40:04.383: E/AndroidRuntime(10227):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
02-08 20:40:04.383: E/AndroidRuntime(10227):    at..`

编辑:这是我的 Game 类的 java 代码。

package com.example.decko;


import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.GridLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class Game extends Activity {
GridLayout parentGrid;
HorizontalScrollView parentLinear;
LinearLayout innerLinearLayout;

private deckWrapper deck; 

ImageButton deckButton;
ImageView pilePosition;

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

    //Fill up and shuffle cards
    this.deck = new deckWrapper();
    //..Done
    // Defining layout hierarchy
    parentGrid = (GridLayout) findViewById(R.id.GridLayout1);
    parentLinear = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
    innerLinearLayout = (LinearLayout) findViewById(R.id.innerLinearLayout);
    //..Done 

    //Define Deck and Card positions
    deckButton = (ImageButton) findViewById(R.id.deck);
    pilePosition = (ImageView) findViewById(R.id.cardpile);
    //..Done

}
public void deckButtonOnClick(View v) {
    this.pickCard();

}
protected void pickCard() {
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageResource(deck.takeCard());
    imageView.setAdjustViewBounds(true);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(6, 0, 6, 0);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    imageView.setLayoutParams(params);
    imageView.setTag("1");
    imageView.setOnClickListener(new MyOnClickListener());  // TODO
    innerLinearLayout.addView(imageView);
}

}

我知道这很乱。当我将主题从常规 api 14 主题更改为 Android.holo 时,出现了问题。我还在 xml 文件中定义了每个按钮的 clicklistener,例如:

 <ImageButton
        android:id="@+id/deck"
        android:layout_column="0"
        android:layout_gravity="center"
        android:layout_marginBottom="50dp"
        android:layout_marginRight="60dp"
        android:layout_row="0"
        android:onClick="deckButtonOnClick"
        android:background="@style/AppBaseTheme"
        android:src="@drawable/deck_1" />
4

1 回答 1

0

我认为您不能为 android:background 指定样式。它期望那里有一个drawable。

于 2013-02-10T17:36:33.497 回答