无法识别启动活动:找不到默认活动

时间:2019-04-16 17:20:35

标签: java android

我是Android的新手,我试图创建一个新的View。 但是我在运行时遇到此错误

  

无法识别启动活动:找不到默认活动

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

2 个答案:

答案 0 :(得分:0)

您的清单文件必须列出您要使用的所有活动,并且您要成为入口点的活动必须具有正确的意图过滤器:

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

答案 1 :(得分:0)

我猜你忘了

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

}
相关问题