-2

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>
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Adrian
  • 178
  • 1
  • 1
  • 13

2 Answers2

0

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>
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

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

}
Community
  • 1
  • 1
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
  • I get this: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference – Adrian Apr 16 '19 at 18:40
  • Also the main problem you're facing is that your `chibiSprite` variable is not initialized when `onDraw` is being called resulting in a null pointer exception. Doing the initialization in the constructor of your class should avoid that problem. – Some random IT boy Apr 16 '19 at 19:01