App Ran Fine, Now Breaking for Seemingly Unknown Reasons
<p>As per <a href="http://stackoverflow.com/questions/4542777/android-sdk-not-compiling-apps-correctly">this</a> question, my app is throwing seemingly random errors. Code that works fine starts to crash whenever I add a significant change (new resource, new code, function call), etc. The activity does not launch at all. The logcat output is telling me that the XML file has an error. Unfortunately, I haven't touched that file. Looking at it closely, it's also telling me something about a color resource not found in an animation XML file. The logcat output is below along with the code:</p>

<pre><code>E/ActivityThread(   54): Failed to find provider info for android.server.checkin
E/AndroidRuntime(  241): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  241): java.lang.RuntimeException: Unable to start activity ComponentInfo{uris.apps.com/uris.apps.com.PlayGame}: android.view.InflateException: Binary XML file line #18: Error inflating class uris.apps.com.ClockTextView
E/AndroidRuntime(  241):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime(  241):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  241):        at android.app.ActivityThread.access$2200(Activi    tyThread.java:119)
E/AndroidRuntime(  241):        at android.app.ActivityThread$H.handleMessage(Ac    tivityThread.java:1863)
E/AndroidRuntime(  241):        at android.os.Handler.dispatchMessage(Handler.ja    va:99)
E/AndroidRuntime(  241):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  241):        at android.app.ActivityThread.main(ActivityThrea    d.java:4363)
E/AndroidRuntime(  241):        at java.lang.reflect.Method.invokeNative(Native     Method)
E/AndroidRuntime(  241):        at java.lang.reflect.Method.invoke(Method.java:5    21)
E/AndroidRuntime(  241):        at com.android.internal.os.ZygoteInit$MethodAndA    rgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  241):        at com.android.internal.os.ZygoteInit.main(Zygot    eInit.java:618)
E/AndroidRuntime(  241):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  241): Caused by: android.view.InflateException: Binary XML fi    le line #18: Error inflating class uris.apps.com.ClockTextView
E/AndroidRuntime(  241):        at android.view.LayoutInflater.createView(Layout    Inflater.java:513)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.createViewFromTag    (LayoutInflater.java:565)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.rInflate(LayoutIn    flater.java:618)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.inflate(LayoutInf    later.java:407)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.inflate(LayoutInf    later.java:320)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.inflate(LayoutInf    later.java:276)
E/AndroidRuntime(  241):        at com.android.internal.policy.impl.PhoneWindow.    setContentView(PhoneWindow.java:198)
E/AndroidRuntime(  241):        at android.app.Activity.setContentView(Activity.    java:1622)
E/AndroidRuntime(  241):        at uris.apps.com.PlayGame.onCreate(PlayGame.java    :41)
E/AndroidRuntime(  241):        at android.app.Instrumentation.callActivityOnCre    ate(Instrumentation.java:1047)
E/AndroidRuntime(  241):        at android.app.ActivityThread.performLaunchActiv    ity(ActivityThread.java:2459)
E/AndroidRuntime(  241):        ... 11 more
E/AndroidRuntime(  241): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(  241):        at uris.apps.com.ClockTextView.&lt;init&gt;(ClockTextV    iew.java:29)
E/AndroidRuntime(  241):        at java.lang.reflect.Constructor.constructNative    (Native Method)
E/AndroidRuntime(  241):        at java.lang.reflect.Constructor.newInstance(Con    structor.java:446)
E/AndroidRuntime(  241):        at android.view.LayoutInflater.createView(Layout    Inflater.java:500)
E/AndroidRuntime(  241):        ... 21 more
E/AndroidRuntime(  241): Caused by: android.content.res.Resources$NotFoundExcept    ion: File res/anim/score_rotate.xml from color state list resource ID #0x7f04000    0
E/AndroidRuntime(  241):        at android.content.res.Resources.loadColorStateL    ist(Resources.java:1813)
E/AndroidRuntime(  241):        at android.content.res.Resources.getColor(Resour    ces.java:626)
E/AndroidRuntime(  241):        at uris.apps.com.ClockTextView.init(ClockTextVie    w.java:42)
E/AndroidRuntime(  241):        ... 25 more
E/AndroidRuntime(  241): Caused by: org.xmlpull.v1.XmlPullParserException: Binar    y XML file line #3: invalid drawable tag set
E/AndroidRuntime(  241):        at android.content.res.ColorStateList.createFrom    XmlInner(ColorStateList.java:144)
E/AndroidRuntime(  241):        at android.content.res.ColorStateList.createFrom    Xml(ColorStateList.java:127)
E/AndroidRuntime(  241):        at android.content.res.Resources.loadColorStateL    ist(Resources.java:1810)
E/AndroidRuntime(  241):        ... 27 more
E/gralloc (   54): [unregister] handle 0x4d08b0 still locked (state=40000001)
</code></pre>

<p>The animation resource is:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator"
    &gt;
  &lt;rotate 
      android:fromDegrees="-45" 
      android:toDegrees="-45" 
      android:pivotX="75%"
      android:pivotY="100%"
      android:duration="1" 
      android:repeatCount="infinite"
      &gt;
  &lt;/rotate&gt;
&lt;/set&gt;
</code></pre>

<p>The PlayGame class is</p>

<pre><code>package uris.apps.com;

import android.widget.*;
import android.widget.AdapterView.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.view.View.*;
import android.content.*;
import android.graphics.PorterDuff.Mode;

/* the PlayGame class coordinates: (1) the TreeGenerator (which is
 * actually the underlying board, I don't know why I called it
 * TreeGenerator), (2) the GameGridView that displays the pictures, (3)
 * the progress bar, (4) the running clock. */

public class PlayGame extends Activity
{
    private GameGridView mGameGridView;
    private TreeGenerator mTree;
    private ImageAdapter mAdapter;
    private ClockTextView mRunningClock;

    //debug
    private TextView mTextView;

    // Menu
    static final private int RESTART = Menu.FIRST;
    static final private int BACK = Menu.FIRST + 1;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //get settings from OptionsMenu
    Intent settings=getIntent();
    int difficulty = settings.getIntExtra("level",
                          TreeGenerator.EASY);
    //create progress bar - must be called before setcontentview
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.play_game);

    //Set up TreeGenerator

    //difficulty = TreeGenerator.HARD;
    mTree = new TreeGenerator(12, difficulty, 3); // no art pieces,
                             // difficulty, no
                             // of stages

    //Set up GridView
    mGameGridView = (GameGridView) findViewById(R.id.game_grid_view);
    mAdapter = new ImageAdapter(this, mTree);
    mGameGridView.setAdapter(mAdapter);

    //Set up RunningClock
    mRunningClock = (ClockTextView) findViewById(R.id.running_clock);
    mRunningClock.initStartTime();

    //Call this method when user selects an image 
    mGameGridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, 
                    View v, 
                    int position, 
                    long id) {
            TreeGenerator mTree = PlayGame.this.mTree;

            //check answer
            boolean result = mTree.checkAnswer(position);
            String text = "Almost!";

            PlayGame.this.mGameGridView.deselect(); //if any

            if ( result ) { // if answer correct
            text = "Correct!";
            //update text view
            PlayGame.this.mGameGridView.flashGreen(position);
            }
            else {
             PlayGame.this.mGameGridView.flashRed(position);
            }

            //check if game complete
            if ( mTree.gameComplete() ) {
            mTree.nextGame();

            //PlayGame.this.mRunningClock.stop();
            //tally score/calculate scores
            //: max_score = no_stages * 1000;
            //: ideal_time = 2 * no_stages + 4;
            //: f(time,stage) = 1/time * max_score * ideal_time;

            float time = PlayGame.this.mRunningClock
                .getRunningTime();
            float max_score = mTree.getStages() * 1000.0f;
            float ideal_time = 2.0f * mTree.getStages() + 4.0f;
            Score.time_bonus = (int) (1.0f / time * max_score * ideal_time);

            PlayGame.this.mRunningClock.initStartTime();

            Intent scoreReport = new 
                Intent(
                   PlayGame.this, 
                   uris.apps.com.ScoreReport.class
                   );
            scoreReport.putExtra("score",Score.score);
            scoreReport.putExtra("incorrect",Score.incorrect_penal);
            scoreReport.putExtra("timebonus",Score.time_bonus);
            scoreReport.putExtra("noerrorbonus",Score.error_bonus);
            startActivity(scoreReport);
            }

            //update pictures
            PlayGame.this.mGameGridView.updateImages();

            //update progress bar
            PlayGame.this.updateProgressBar();

            if ( MyDebug.playGameDebug ) {
            //say if correct or not
            Toast.makeText(PlayGame.this, 
                       text + " " + position,
                       Toast.LENGTH_SHORT).show();
            }
        }
        });

    if ( MyDebug.playGameDebug) {
        Toast.makeText(PlayGame.this, 
                   "Level: "+String.valueOf(difficulty), 
                   Toast.LENGTH_SHORT).show();

        mTextView = (TextView) findViewById(R.id.textview);

        mTextView.setText(
                      mTree.toString() 
                      //+ "\n" + "Item sel: " + position
                      );
    }

    //init progress bar
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
    }
</code></pre>

<p>play_game.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;
  &lt;uris.apps.com.GameGridView 
      android:id="@+id/game_grid_view"
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:columnWidth="90dp"
      android:numColumns="auto_fit"
      android:verticalSpacing="10dp"
      android:horizontalSpacing="10dp"
      android:stretchMode="columnWidth"
      android:gravity="center"
      /&gt;
  &lt;uris.apps.com.ClockTextView
      android:id="@+id/running_clock"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#ffffff"
      android:textSize="50sp"
      /&gt;
  &lt;!--Debug --&gt;
  &lt;TextView
      android:id="@+id/textview"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>ClockView:</p>

<pre><code>package uris.apps.com;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
import android.os.SystemClock;

public class ClockTextView extends TextView {

    private Paint textPaintColor;
    private long startTime;
    private float secs;

    public ClockTextView (Context context, AttributeSet ats, int ds) {
    super(context, ats, ds);
    init();
    }

    public ClockTextView (Context context) {
    super(context);
    init();
    }

    public ClockTextView (Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    }

    public void initStartTime() {
    startTime = SystemClock.uptimeMillis();
    }

    private void init() {
    // Get a reference to our resource table.
    Resources myResources = getResources();

    // Create the paint brushes we will use in the onDraw method.
    textPaintColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaintColor.setColor(myResources.getColor(R.color.clockTextColor));
    textPaintColor.setTextSize( 50 );

    startTime = SystemClock.uptimeMillis();

    // // Get the paper background color and the margin width.
    // paperColor = myResources.getColor(R.color.notepad_paper);
    //margin = myResources.getDimension(R.dimen.notepad_margin);
    }

    public float getRunningTime() {
    return secs;
    }

    @Override
    public void onDraw(Canvas canvas) {

    //number of milliseconds elapsed
    long curTime = SystemClock.uptimeMillis() - startTime;
    //convert to seconds
    secs = curTime / 1000.0f;
    //Round to 1 decimal place
    //float p = (float) Math.pow(10,1);
    secs = (float) (Math.round(secs*10.0f)/10.0f);

    canvas.drawText(String.valueOf(secs), 60, 60, textPaintColor);
    // Color as paper
    // canvas.drawColor(paperColor);

    // // Draw ruled lines
    // canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);
    // canvas.drawLine(0, getMeasuredHeight(), 
    //                    getMeasuredWidth(), getMeasuredHeight(), 
    //                    linePaint);

    // // Draw margin
    // canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);

    // // Move the text across from the margin
    // canvas.save();
    // canvas.translate(margin, 0);

    // Use the TextView to render the text.
    super.onDraw(canvas);
    //canvas.restore();
    invalidate();
    }
}
</code></pre>

<p>and finally the resource that defines the clock color:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;resources&gt;
  &lt;color name="clockTextColor"&gt;#FFFFFF&lt;/color&gt;
&lt;/resources&gt;
</code></pre>
