所以我一直在試圖從這本書中學習,並且我完全按照它的說法做了(至少我是這麼認爲的),但該應用程序並未顯示在AVD中。 我有2班在我的包名爲(com.example.crazyeights)
: CrazyEightsActivity.java
& CrazyEightsView.java
下CrazyEightsActivity
,我有:程序化的Android應用程序不顯示在AVD中
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);
}
}
我已經做了一個「測試-app「只是爲了看看它是否適用於我的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>
我複製並將其替換爲androidManifest.xml中的部分但是,我收到一個錯誤:元素類型「activity」必須後跟任一屬性specifica tions,「>」或「/>」 –
user2789610
Put> After ... CrazyEightsActivity「 – Melquiades
嗯...我做對了嗎? (我用我的.xml編輯了我原來的帖子) – user2789610