Reputation: 19
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>
Upvotes: 0
Views: 128
Reputation: 76564
Change this in your 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
Upvotes: 2
Reputation: 2767
It's telling you that you need to add the com.lania.saludandroidte.Menu
Activity. 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".
Upvotes: 0
Reputation: 2600
You need to declare the new activity in your Manifest.
<activity android:name="com.lania.saludandroidte.RegisterActivity" />
Upvotes: 0