Reputation: 4045
I'm getting an ActivityNotFoundException in my Android Application.. Here's the code snippet I have put to call the activity :
Intent i = new Intent();
i.putExtra("NAME", username.getText().toString());
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());
startActivity(i);
my AndroidManifest.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rangde"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<activity android:name=".firstActivity" 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:label="@string/app_name" android:name=".SecondActivity" />
<activity android:label="@string/app_name" android:name=".WelcomeActivity" />
</application>
</manifest>
When I execute the code snippet with the intent, I get the following exception.
E/AndroidRuntime(731): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.rangde/WelcomeActivity}; have you declared this activity in your AndroidManifest.xml?
Can someone tell me what I'm doing wrong?
Upvotes: 0
Views: 643
Reputation: 1562
Intent intent = new Intent().setClass(Class1.this, Class2.class);
i.putExtra("NAME", username.getText().toString());
startActivity(intent);
Upvotes: 0
Reputation: 691
instead of writing
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());
try with
i.setClassName(getPackageName(), SecondActivity.class.getName());
SecondActivity.class.getSimpleName() returns only name of the class.
if u write SecondActivity.class.getName() get fully qualified class name(with the package name)
Upvotes: 0
Reputation: 132982
use this
String packageName = this.getPackageName();
i.setClassName(packageName ,packageName + "." + SecondActivity.class.getSimpleName());
instead of
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());
Upvotes: 0
Reputation: 32222
Call your SecondActvity like This
Intent i = new Intent(this,SecondActivity.class);
i.putExtra("NAME", username.getText().toString());
startActivity(i);
Upvotes: 0
Reputation: 3937
//set your classname here
Intent i = new Intent(firstActivity.this, SecondActivity.class);
i.putExtra("NAME", username.getText().toString());
startActivity(i);
Upvotes: 2