简体   繁体   English

为什么我在android中的活动出错?

[英]Why I am getting error with my activity in android?

I declare both of my activity class in AndroidManifest.xml file them when I run my application it stop unfortunately with this error message:- 我在运行应用程序时在AndroidManifest.xml文件中声明了我的两个活动类,不幸的是,此错误消息停止了:-

 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidtutorialpoint.androidobservablescrollview/com.androidtutorialpoint.androidobservablescrollview.ParallaxToolbarScrollViewActivity}; have you declared this activity in your AndroidManifest.xml?

This is my manifest file:- 这是我的清单文件:

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

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

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".ParallaxToolbarScrollViewActivity"
            android:label="@string/title_activity_parallaxtoolbarscrollview"
            android:theme="@style/AppTheme.Toolbar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="com.androidtutorialpoint.androidobservablescrollview" />
            </intent-filter>
        </activity>

    </application>

</manifest>

My Activity class names are:- 我的活动类名称为:-

  1. MainActivity 主要活动
  2. ParallaxToolbarScrollViewActivity ParallaxToolbarScrollViewActivity

You placed it in the wrong location it should be inside the application tag. 您将其放置在应位于应用程序标记内的错误位置。 All your <activity... /> tags should be placed under the <application.. /> tag. 您所有的<activity... />标记都应放在<application.. />标记下。

Hope this helps! 希望这可以帮助!

Clean your build and rebuild the project. 清理构建并重新构建项目。 If you are using instance run android studio feature then disable this for avoid this problem 如果您使用实例运行android studio功能,请禁用此功能以避免出现此问题

Remove 去掉

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

                <category android:name="com.androidtutorialpoint.androidobservablescrollview" />
            </intent-filter>

otherwise change your package name insted of 否则,更改您的包裹名称

com.androidtutorialpoint.androidobservablescrollview com.androidtutorialpoint.androidobservablescrollview

Remove intent-filter tag from your second activity. 从第二个活动中删除intent-filter标签。

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

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

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

        <activity
            android:name=".ParallaxToolbarScrollViewActivity"
            android:label="@string/title_activity_parallaxtoolbarscrollview"
            android:theme="@style/AppTheme.Toolbar">
        </activity>

    </application>

</manifest>

Put intent filter to single activity which you want to start first. 将意图过滤器放到要首先开始的单个活动上。 If launching activity is MainActivity, then remove intent filter from ParallaxToolbarScrollViewActivity. 如果启动活动为MainActivity,则从ParallaxToolbarScrollViewActivity中删除意图过滤器。 Or recheck the category line ** 或重新检查类别行**

"com.androidtutorialpoint.androidobservablescrollview" “ com.androidtutorialpoint.androidobservablescrollview”

** **

<activity
        android:name=".ParallaxToolbarScrollViewActivity"
        android:label="@string/title_activity_parallaxtoolbarscrollview"
        android:theme="@style/AppTheme.Toolbar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="com.androidtutorialpoint.androidobservablescrollview" />
        </intent-filter>
    </activity>

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

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