Reputation: 31
Suddenly I get the following error:
android.content.ActivityNotFoundException: Unable to find explicit activity class.
Although I have declared in the file AndroidManifest.xml
all the activities of my application.
Does anyone know how to fix this error?
Thank you all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uniparthenope.jacoe.homework_tmm">
<uses-feature android:name="android.hardware.camera"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SignUpActivity"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
</application>
</manifest>
This is my MainActivity.java
, in which I call the activity SignUpActivity.java
through an Intent.
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
ChatFragment chatFragment;
CallsFragment callsFragment;
StatusFragment statusFragment;
PhotoFragment photoFragment;
String[] tabTitle = {"FOTO", "CHIAMATE", "CHAT", "STATO"};
int[] unreadCount = {0, 0, 5, 0};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab);
Toolbar toolbarapp = (Toolbar) findViewById(R.id.Whatsapp_tmm_toolbar);
setSupportActionBar(toolbarapp);
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setOffscreenPageLimit(4);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tablayout);
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
viewPager.setCurrentItem(position, false);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_button, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.login:
Intent login = new Intent(this, SignUpActivity.class);
startActivity(login);
finish();
return true;
Upvotes: 2
Views: 5737
Reputation: 347
I had this issue on Android Studio 4.0.1, android gradle 4.0.1 build gradle 6.1.1 and could not resolve it with the answers here.
What eventually fixed it for me was going to my app folder and deleting the entire .gradle folder, then invalidating cache and restarting. Normal cache invaldiation didn't work. Rebuilding, cleaning, syncing with gradle: None of it worked without me going in and deleting the entire .gradle folder.
Upvotes: 1
Reputation: 799
try to sync with " sync Project with Gradle files" inside Android Studio->Files->Sync Project with Gradle Files.
Sometime we miss to do this after having changes to Manifest.
Upvotes: 12
Reputation: 111
Try to give the activity name as the package name and the activity name. like,
<activity name="com.uniparthenope.jacoe.homework_tmm.MainActivity" />
this will take the id from the described location.
Upvotes: -1