Java Eclipse Juno Android错误,styles.xml错误

Java Eclipse Juno Android错误,styles.xml错误,java,android,xml,eclipse-adt,Java,Android,Xml,Eclipse Adt,我最近购买了Sams自学Android游戏编程24小时。我目前正在学习设置位图图像集的动画。完整代码为: package com.example.demojava1; import java.io.IOException; import java.io.InputStream; import android.app.Activity; import android.content.Context; import android.content.res.AssetManager; import

我最近购买了Sams自学Android游戏编程24小时。我目前正在学习设置位图图像集的动画。完整代码为:

package com.example.demojava1;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;

public class MainActivity extends Activity {
/****************************************************************
 * This portion of code represents the "outer" main program.    *
 *                                                              *
 * Events here are passed on to the drawing sub-class.          *
 ****************************************************************/
//defines the drawing sub-class object
DrawView drawView;

//onCreate is called any time the program resumes
@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    //create the drawing object
    drawView = new DrawView(this);
    setContentView(drawView);
}

//handle resume/focus events
@Override public void onResume() {
    super.onResume();
    //pass the resume event on to the sub-class
    drawView.resume();
}

//handle pause/minimize events
@Override public void onPause() {
    super.onPause();
    //pass the pause event on to the sub-class
    drawView.pause();
}

/*************************************
 * End of "outer" main program code. *
 *************************************/


/****************************************************************
 * This code represents the new DrawView subclass which handles *
 * the real-time loop, updates, and drawing, i.e. the game      *
 * code. Note that this class now implements Runnable to give   *
 * it a threaded loop.                                          *
 ****************************************************************/

public class DrawView extends SurfaceView implements Runnable {
    //define the game loop thread
    Thread gameloop = null;

    //define the surface holder
    SurfaceHolder surface;


    //define the running variable 
    volatile boolean running = false;

    //the asset manager handles resource loading
    AssetManager assets = null;
    BitmapFactory.Options options = null;
    Bitmap gKnight[];
    int frame = 0;

    //this is the DrawView class constructor
    public DrawView(Context context) {
        super(context);

        //get the SurfaceHolder object to supply a context
        surface = getHolder();

        //create the asset manager object
        assets = context.getAssets();

        //set bitmap color depth option
        options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        //create the bitmap array for animation
        gKnight = new Bitmap[8];

        //load the knight bitmaps
        try {
            for (int n = 0; n<8; n++) {
                String filename = "walking" + Integer.toString(n+1) + ".bmp";
                InputStream istream = assets.open(filename);
                gKnight[n] = BitmapFactory.decodeStream(istream,null,options);
                istream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //custom resume method called by outer class
    public void resume() {
        running = true; 
        gameloop = new Thread(this);
        gameloop.start();
    }

    //custom pause method called by outer class
    public void pause() {
        running = false;
        while (true) {
            try {
                //just keep doing this until app has focus
                gameloop.join();
            }
            catch (InterruptedException e) {}

        }
    }

    //this is the threaded method
    @Override public void run() {

        //this is the game loop!
        while (running) {

            //make sure surface is usable (it's asynchronous)
            if (!surface.getSurface().isValid())
                continue;

            //request the drawing canvas
            Canvas canvas = surface.lockCanvas();

            /************************************************************
             * We should really make sure canvas is not null here       *
             * before continuing, but if canvas is invalid then         *
             * the game will cease anyway.                              *
             ************************************************************/

            //draw one frame of animation from the knight array
            canvas.drawColor(Color.rgb(85,107,47));
            canvas.drawBitmap(gKnight[frame], 0, 0, null);

            //draw the knight scaled larger
            Rect dest = new Rect(100, 0, 300, 200);
            canvas.drawBitmap(gKnight[frame], null, dest, null);

            //draw the knight scaled REALLY BIG!
            dest = new Rect(200, 0, 800, 600);
            canvas.drawBitmap(gKnight[frame], null, dest, null);

            //release the canvas
            surface.unlockCanvasAndPost(canvas);

            //go to the next frame of animation
            frame++;
            if (frame > 7) frame = 0;

            try {
                //slow down the animation
                Thread.sleep(50);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
} // end of DrawView sub-class code;
} //end of main

代码读取时出现错误:

错误状态为:
错误:检索项的父项时出错:未找到与给定名称“Theme.AppCompat.Light”匹配的资源。

有人能帮忙吗? 如果你有一个解决方案的话,虽然我在Java方面越来越好,但我从来没有用xml编写过代码,而且我对Android完全是新手,所以这对我来说很粗糙。漫游越详细越好。
谢谢

你好,frank,您需要AppCompat for Theme.AppCompat.Light,请执行以下步骤

  • 文件->导入(android sdk\extras\android\support\v7)
  • 选择“appcompat”项目->属性->Android
  • 在“添加”部分中,选择“appCompat”

  • 您好,frank,您需要AppCompat for Theme.AppCompat.Light请执行以下步骤

  • 文件->导入(android sdk\extras\android\support\v7)
  • 选择“appcompat”项目->属性->Android
  • 在“添加”部分中,选择“appCompat”

  • 您好,frank,您需要AppCompat for Theme.AppCompat.Light请执行以下步骤

  • 文件->导入(android sdk\extras\android\support\v7)
  • 选择“appcompat”项目->属性->Android
  • 在“添加”部分中,选择“appCompat”

  • 您好,frank,您需要AppCompat for Theme.AppCompat.Light请执行以下步骤

  • 文件->导入(android sdk\extras\android\support\v7)
  • 选择“appcompat”项目->属性->Android
  • 在“添加”部分中,选择“appCompat”

  • AppCompat是一个库项目。您需要在android项目中引用库项目。这很有效,谢谢!然而,我最终还是换了java教科书,找到了一本效果更好的。不过,还是要谢谢你。AppCompat是一个库项目。您需要在android项目中引用库项目。这很有效,谢谢!然而,我最终还是换了java教科书,找到了一本效果更好的。不过,还是要谢谢你。AppCompat是一个库项目。您需要在android项目中引用库项目。这很有效,谢谢!然而,我最终还是换了java教科书,找到了一本效果更好的。不过,还是要谢谢你。AppCompat是一个库项目。您需要在android项目中引用库项目。这很有效,谢谢!然而,我最终还是换了java教科书,找到了一本效果更好的。不过还是要谢谢你。
    <resources>
    
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>
    
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>