繁体   English   中英

无法找到明确的活动类,是否已在AndroidManifest.xml中声明了该活动?

[英]Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml?

我想打开下一个活动,但出现以下错误

android.content.ActivityNotFoundException:无法找到显式的活动类{com.example.pc.lovequoteandcalculator / int}; 您是否在AndroidManifest.xml中声明了此活动?

我的Manifest.xml是

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

<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">
    <activity android:name=".MainActivity">
        <intent-filter>

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

这就是我开始新活动的方式

val btn = findViewById<View>(R.id.btnlovecal) as Button btn.setOnClickListener { 
    startActivity(
            Intent(this@MainActivity,activity_lovecalculate::class.java)
        ) 
} 

有人可以指出我在这里想念什么吗?

您似乎通过以下方式调用了错误的活动:

 Intent(this@MainActivity,activity_lovecalculate::class.java)

试图调用activity_lovecalculate活动。 但是您只有:

<activity android:name=".lovecalculate" />

因此,尝试使用lovecalculate进行以下操作:

val btn = findViewById<View>(R.id.btnlovecal) as Button btn.setOnClickListener { 
    startActivity(
            Intent(this@MainActivity, lovecalculate::class.java)
        ) 
} 

PS:请对类名使用正确的编码样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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