简体   繁体   English

Android 清单中无法识别活动

[英]Activity Not recognized in Android Manifest

I'm trying to make a simple program where if I go and click a button in my app a new activity pops up that asks to input a browser.我正在尝试制作一个简单的程序,如果我点击应用程序中的一个按钮,则会弹出一个要求输入浏览器的新活动。 Here's the Exception I keep recieving:这是我不断收到的异常:

02-26 04:38:11.900 1937-1937/? E/AndroidRuntime: FATAL EXCEPTION: main
    android.content.ActivityNotFoundException: Unable to find explicit activity class
        {com.course.example.widgets/com.course.example.widgets.WebLookup};
    have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
        at android.app.Activity.startActivityForResult(Activity.java:3370)
        at android.app.Activity.startActivityForResult(Activity.java:3331)
        at android.app.Activity.startActivity(Activity.java:3566)
        at android.app.Activity.startActivity(Activity.java:3534)
        at com.course.example.widgets.Widgets.onClick(Widgets.java:139)
        at android.view.View.performClick(View.java:4204)
        at android.view.View$PerformClick.run(View.java:17355)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

Here's my manifest xml:这是我的清单 xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.course.example.widgets"
      android:versionCode="1"
      android:versionName="1.0">

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Widgets"
                  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="com.course.example.widgets.WebLookup"
                    android:label="@string/app_name"/>
    </application>
    <uses-sdk android:minSdkVersion="17" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
</manifest> 

Here's the code that actually starts the activity:这是实际启动活动的代码:

case R.id.webButton:{
    Intent webLookup = new Intent(this, WebLookup.class);
    startActivity(webLookup);
    break;

It's in a switch block that is for determining 3 other button actions but I didn't think it was relevant.它位于一个用于确定其他 3 个按钮操作的开关块中,但我认为它无关紧要。

Here's a picture of XML file and my two Java files in navigator on left.这是左侧导航器中 XML 文件和我的两个 Java 文件的图片。

在此处输入图片说明

Declare this Activity to AndroidMenifest , you error might be have not written package name before activity name将此 Activity 声明为 AndroidMenifest ,您的错误可能是没有在 Activity 名称之前写入包名称

<activity
            android:name=".WebLookup" //write package name before activity name
            android:configChanges="orientation" //optional
            android:screenOrientation="portrait" //optional
            android:windowSoftInputMode="adjustResize" /> //optional

If you are adding this activity class manually, verify that the class is set to public.如果您手动添加此活动类,请验证该类是否设置为公共。 This way the AndroidManifest.xml should automatically show your activity class as a possible option.这样 AndroidManifest.xml 应该自动显示您的活动类作为一个可能的选项。

public MyActivityClass extends AppCompatActivity{
...
}

If you have not included the package path at the top of the class you wont be able to reference it in the manifest, eg如果您没有在类的顶部包含包路径,您将无法在清单中引用它,例如在此处输入图片说明

use

<activity android:name="com.course.example.widgets.WebLookup"
                    android:label="@string/app_name"/>

the full name of the activity is much more comfortable in practice.活动的全名在实践中要舒服得多。

com.course.example.widgets.WebLookup mean the full path to your Activity class file. com.course.example.widgets.WebLookup 表示您的 Activity 类文件的完整路径。

You have to provide complete package name like this你必须像这样提供完整的包名

<activity android:name="com.course.example.widgets.WebLookup"
                    android:label="@string/app_name"/>

Otherwise it will not detect your class whom to transfer the intent.否则它不会检测你的班级向谁转移意图。

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

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