简体   繁体   English

ActivityNotFoundException Android应用程序

[英]ActivityNotFoundException Android App

Total noob here in the programming world and I'm just trying to figure out, why when I click on a button for a login screen on my app, it just won't run and it shuts down "unexpectedly" in the emulator. 编程世界中的总菜鸟,我只想弄清楚,为什么当我点击我的应用程序上的登录屏幕的按钮时,它只是不会运行并且它在模拟器中“意外地”关闭。

Here's the code: 这是代码:

    package com.lania.saludandroidte;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import android.widget.TextView;

public class LoginActivity extends Activity implements View.OnClickListener{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        Button log = (Button) findViewById(R.id.btnLogin);
        log.setOnClickListener((OnClickListener) this);

        TextView registerScreen = (TextView) findViewById(R.id.link_to_register);

        // Listening to register new account link
        registerScreen.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // Switching to Register screen


                Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
                startActivity(i);
            }
        });
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId() == R.id.btnLogin) {
            startActivity(new Intent(LoginActivity.this, Menu.class));
        }
    }



}

Here's the log: 这是日志:

This is what I get: 这就是我得到的:

    05-06 13:07:05.155: E/AndroidRuntime(277): FATAL EXCEPTION: main
05-06 13:07:05.155: E/AndroidRuntime(277): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.lania.saludandroidte/com.lania.saludandroidte.Menu}; have you declared this activity in your AndroidManifest.xml?
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.app.Activity.startActivityForResult(Activity.java:2817)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.app.Activity.startActivity(Activity.java:2923)
05-06 13:07:05.155: E/AndroidRuntime(277):  at com.lania.saludandroidte.LoginActivity.onClick(LoginActivity.java:41)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.view.View.performClick(View.java:2408)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.view.View$PerformClick.run(View.java:8816)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.os.Handler.handleCallback(Handler.java:587)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
05-06 13:07:05.155: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-06 13:07:05.155: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
05-06 13:07:05.155: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
05-06 13:07:05.155: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-06 13:07:05.155: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-06 13:07:05.155: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)

Manifest file: 清单文件:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name= "com.lania.saludandroidte.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="com.lania.saludandroidte.Glucosa"
            android:label="@string/title_activity_glucosa" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name="com.lania.saludandroidte.LoginActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.sanikte.proyecto.Menu" />
        <activity android:name="com.sanikte.proyecto.RegisterActivity" />
    </application>

</manifest>

Change this in your AndroidManifest.xml: 在AndroidManifest.xml中更改此内容:

 <activity android:name="com.sanikte.proyecto.Menu" />

to this: 对此:

 <activity android:name="com.lania.saludandroidte.Menu" />

You have declared it with the wrong package. 你用错误的包声明了它。 You can tell this because in your LoginActivity.java where you say Menu.class it is not qualified with the full package and if you look at the import list it is not imported under com.sanikte.proyecto therefore Menu.java must be in the same package as LoginActivity.java 你可以告诉这个,因为你在LoginActivity.java中你说Menu.class它不符合完整的包,如果你查看导入列表它不是在com.sanikte.proyecto下导入的,因此Menu.java必须在与LoginActivity.java相同的包

您需要在Manifest中声明新活动。

<activity android:name="com.lania.saludandroidte.RegisterActivity" /> 

It's telling you that you need to add the com.lania.saludandroidte.Menu Activity. 它告诉你需要添加com.lania.saludandroidte.Menu活动。 It appears that you have registered com.sanikte.proyecto.Menu , but its package "com.sanikte.proyecto" does not match the actual Activity's package, "com.lania.saludandroidte". 您似乎已注册com.sanikte.proyecto.Menu ,但其软件包“com.sanikte.proyecto”与实际的Activity软件包“com.lania.saludandroidte”不匹配。

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

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