簡體   English   中英

無法識別啟動活動:未找到默認活動

[英]Could not identify launch Activity: Default Activity wasn't found

我是 Android 新手,我嘗試創建一個新視圖。 但我在運行時收到此錯誤

無法識別啟動活動:未找到默認活動

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.bamlineapps.dungeonexplorer.DungeonExplorer xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dungeonView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

    </com.bamlineapps.dungeonexplorer.DungeonExplorer>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

這是我的 android 清單,因為我認為錯誤來自這里:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.bamlineapps.dungeonexplorer">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

你的清單文件必須列出你想使用的所有活動,你想成為你的入口點的活動需要有正確的意圖過濾器:

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

我猜你忘了

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas); // <- this line
    // Your code here
}

而且我只能猜測,因為問題中缺少一些重要數據 - 您能否附上問題的控制台上打印的崩潰日志/錯誤?

更新

嘗試空檢查變量並在類的構造函數中初始化內容,如下所示:

public class YourView extends ImageView { // I don't know; provide more info

    private Bitmap chibiSprite;

    public YourView(Context context) {
        super(context);
        chibiSprite = BitmapFactory.decodeResource(getResources(), R.drawable.chibi_sprite);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(canvas != null)
            drawCharacter(canvas);
    }

    public void drawCharacter(Canvas canvas) {
        // Customize these three
        float location_x = 100F;
        float location_y = 100F;
        Paint custom_paint = null; 
        canvas.drawBitmap(chibiSprite, location_x, location_y, custom_paint);
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM