编程世界中的总菜鸟我正在试图找出,为什么当我点击我的应用程序上的登录屏幕的按钮时,它将无法运行并且它“意外地”关闭仿真器。
以下是代码:
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>
答案 0 :(得分: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
必须与{{1}}
答案 1 :(得分:0)
您需要在Manifest中声明新活动。
<activity android:name="com.lania.saludandroidte.RegisterActivity" />
答案 2 :(得分:0)
它告诉您需要添加com.lania.saludandroidte.Menu
活动。您似乎已注册com.sanikte.proyecto.Menu
,但其软件包“com.sanikte.proyecto”与实际的Activity软件包“com.lania.saludandroidte”不匹配。