0

在编程世界中完全是菜鸟,我只是想弄清楚,为什么当我在我的应用程序上单击登录屏幕的按钮时,它就无法运行并且它在模拟器中“意外”关闭。

这是代码:

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



}

这是日志:

这就是我得到的:

    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)

清单文件:

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

3 回答 3

2

在您的 AndroidManifest.xml 中更改它:

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

对此:

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

你用错误的包声明它。您可以告诉这一点,因为在LoginActivity.java您所说的地方,Menu.class它不符合完整包的条件,如果您查看导入列表,则它没有被导入,com.sanikte.proyecto因此Menu.java必须与LoginActivity.java

于 2013-05-06T18:59:53.170 回答
0

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

<activity android:name="com.lania.saludandroidte.RegisterActivity" /> 
于 2013-05-06T18:53:14.527 回答
0

它告诉您需要添加com.lania.saludandroidte.Menu活动。看来您已经注册com.sanikte.proyecto.Menu了,但它的包“com.sanikte.proyecto”与实际 Activity 的包“com.lania.saludandroidte”不匹配。

于 2013-05-06T18:59:48.913 回答