Frage

Can anyone explain to me what the following logcat complains about?

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..`

EDIT: Here is my java code for the Game class.

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);
}

}

I know it is messy. The problem occured when i changed my theme from regular api 14 theme to Android.holo. I also defined each buttons clicklistener in the xml file like :

 <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" />
War es hilfreich?

Lösung

I don't think you can specify a style for android:background. It expects a drawable there.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top