任何人都可以向我解释以下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" />
答案 0 :(得分:0)
我认为你不能为android:background指定一个样式。它希望那里有一个可绘制的。