简体   繁体   中英

Could not identify launch Activity: Default Activity wasn't found

I'm new to Android and I have tried to create a new View. But I get this error on run

Could not identify launch Activity: Default Activity not found

<?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>

Here is my android manifest as I think that the error comes from here:

<?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>

Your manifest file must list all activities you want to use and the one you want to be your entry point needs to have right intent filter:

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

I'm guessing that you've forgot to

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

And I can only guess because there's some important data missing in the question - Could you please attach the crash Logs/errors printed on console on the question?

Update

Try null checking your variables and initializing stuff in the constructor of your class like so:

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);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM