程序化的Android应用程序不会在AVD中显示

时间:2013-12-13 21:10:52

标签: java android sdk

所以我一直试图从这本书中学习,而且我完全按照它的说法做了(至少我是这么认为的),但该应用程序没有在AVD中显示。 我的包中有2个名为(com.example.crazyeights)的类: CrazyEightsActivity.java& CrazyEightsView.javaCrazyEightsActivity下,我有:

package com.example.crazyeights;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class CrazyEightsActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CrazyEightsView CrazyEightsView = new CrazyEightsView(this);
        setContentView(R.layout.activity_main);
    }
}

CrazyEightsView.java下我有:

package com.example.crazyeights;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class CrazyEightsView extends View
{
    private Paint redPaint;
    private int circleX;
    private int circleY;
    private float radius;

public CrazyEightsView(Context context) {
        super(context);
        redPaint = new Paint();
        redPaint.setAntiAlias(true);
        redPaint.setColor(Color.RED);
        circleX = 100;
        circleY = 100;
        radius = 30;
    }
    @Override
    protected void onDraw(Canvas canvas)
    {
        canvas.drawCircle(circleX, circleY, radius, redPaint);
    }

}

我已经制作了一个“测试应用程序”,只是为了看看它是否适用于我的AVD。 谢谢你的帮助!

编辑:我的AndroidManifest.xml目前看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.crazyeights"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.crazyeights.CrazyEightsActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    </application>

</manifest>

2 个答案:

答案 0 :(得分:2)

你还有清单文件吗?

如果您有清单,您是否将新活动添加到清单中,如下所示:

    <activity>
        android:name="com.example.crazyeights.CrazyEightsActivity"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

答案 1 :(得分:0)

你必须对CrazyEightsActivity这个类进行一些更改

1)OnCreateMethod

   @Override     
         public void onCreate(Bundle savedInstanceState) {   
         super.onCreate(savedInstanceState);  
         setContentView(new CrazyEightsView(CrazyEightsActivity.this));
}