I am getting an error which reads The activity 'MainActivity' is not declared in AndroidManifest.xml
What is the problem here?
I got this error when moving a lot of files, to fix just resync your gradle files.
File->Sync Project with Gradle Files
Try to go to File->Invalidate Caches / Restart and choose invalidate and restart ,it worked for me
Sometimes when moving or renaming files, you can have broken XML files. My case that the ic_launcher.xml was corrupt. I regenerated that and worked just fine.
Check every XML in your proyect.
You are most likely just missing the below from your AndroidManifest:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
Here is a full example of an AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pejner.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
this happened for me when my laptop suddenly shut down when working with project. if you see your activity declaration in your manifest, do not open any xml files. they maybe broken and corrupt after opening files.
so do these steps:
delete all .iml files from your project
go to Files => invalidate cache / Restart
Rebuild your project gradle
finally if problem still exists, go to Files => Sync project with gradle files
https://stacklearn.ir
This can be only two reason,
the bold one, missing extend statement
class MainActvity extends AppCompatActivity
or
you are using a wrong package name to register your activity so just in this case use ALT+Space then studio will show the options itself.
All of my XML file were cut in half for some reason, I'm not sure when it happened (I use Git VCS, so maybe that). I had to go through each of them and restore the code.
It have three ways to resolve
1:-
Go File->Invalidate Caches / choose invalidate and restart ,it works
2:-
If you make MainActivity make sure you have onCreate method in it and extend with AppCompatActivity .
3:- And last option sync project with Gradle file
Follow these steps:
File => Invalidate Caches / Restart...
Files => Sync project with gradle files
If the steps above don't work, write:
com.example.(project name).MainActivity
It should work, worked for me.
For those cases the you recently changed the android:allowBackup settings, make sure you also set the tools:replace="android:allowBackup" in case some of your dependency have it declared in them to override it. I wouldn't know this solution until I manually execute Gradle > app > cleanbuild > lintFix
The exact error I received was:
Error: Attribute application#allowBackup value=(false) from AndroidManifest.xml:41:9-36
is also present at [com.kaopiz:kprogresshud:1.2.0] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:39:5-254:19 to override.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.YOURPAKAGE">
<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/Theme.YOURPAKAGE">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
NOTE:
Replace your AndroidManifest.xml file code with the above code and you just have to change the name of your package at those places where I have mentioned (YOURPAKAGE) hopefully the problem will be solved
replace in your AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.justjava">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
</application>
</manifest>
You should try this
<activity
android:name="com.example.stockquote.StockInfoActivity"
android:label="#string/app_name"
/>
For more detail you can check hereActivity declare
Thanks everyone for taking the time out to help a beginner.
I found out that I had somehow misspelled the Package in MainActivity.java
When I corrected it the error was gone.
Thank you all.
I was getting an error "The activity 'MainActivity' is not declared in AndroidManifest.xml", even though it was correct in the manifest file.
My problem was that when I created the project I had to mark the item "Use AndroidX artifacts".
If you see that error occur after upgrading versions of IntelliJ IDEA or Android Studio, or after Generating a new APK, you may need to refresh the IDE's cache.
File -> Invalidate Caches / Restart...
I was working on my project suddenly my laptop restarts i tried lot of methods but i was not able to fix it.
But at the end i did it
do these steps and let me know it is working or not?
1. File > Invalidate Cache and restart the the android studio
2. Build > Clean Project and then Rebuild project
3. Sync project with gradle files
if it is still showing you error try these steps
1. Create new activity
Remember to clink on checkBox Launcher Activity
Hope this will Fix your problem
In the end go to AndroidManifest.xml and change New activity Default to previous activity
In my case, none of the answers helped. Luckily, I remembered that I added a variable in build.gradle, which I tried to access from MainActivity.
Problem was that this new variable wasn't present in AndroidManifest.xml. Once I added the variable to AndroidManifest.xml, the problem was solved.
This is an odd one. For me I had to open Edit Configurations (run configuration) and select <no module> under the Module drop-down. Then reselect my project under the Module drop-down and Apply. It the built and ran just fine.
Had the same problem with a project which I just downloaded the starter code for
an app , everything looked fine in the AndroidManifest.xml , I just deleted the com.example.android.(yourappname).MainActivity and wrote .dMainActivity and it worked.
I keep getting this message when trying to run the emulator, even though I've put the launcher activity in my manifest.
Does anyone have an idea what I'm doing wrong?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.libsdl.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="org.libsdl.app.SDLActivity"
android:label="#string/app_name" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Resolved: After some more mucking around in my files, I found that there were multiple AndroidManifest.mk files and I had put the activity in the wrong one. (I had this in the mk file located in the bin folder, instead of the one in root.)
I was having this same issue, and the OP's edit at the bottom of the post was what fixed it. (I would have upvoted, but I do not have any reputation points at this time).
To clarify for anyone in the future: it appears that Eclipse will automatically create a duplicate of the AndroidManifest.xml in the bin directory. This copy is automatically generated off of the one you are supposed to edit on the root directory.
If you edit the manifest in the bin directory, Eclipse will not give you any warning that you are editing the wrong file. You can even save to it, and run validate to ensure that there are no errors. When you run the program, it will actually be overwritten, but for some reason Eclipse tends not to prompt you that the contents have been overridden while you still have the file open.
I am following he tutorial from this site: http://developer.android.com/training/basics/firstapp/creating-project.html, but when I run the default program in eclipse when an android project is created, it gives me the error R could not be found. To fix this, I commented out the lines with R and ran it again, but now it gives me the error: Could not find MyFirstApp.apk!... I have tried all other solutions on this site, but none of them work. If anybody knows how to fix this, please let me know!
here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myfirstapp.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>
</application>
</manifest>
When your .R class could not be found, there is an error in your project - commenting out the lines with the .R class does not fix the problem.
Perhaps you just have to clean your workspace (Project > Clean...) or delete the bin and gen folder in your project, they should be rebuilt automatically.
Look at the Problems tab next to the Console tab where you get the errors and take a look at the messages.
when I had originally installed the android sdk it installed to some folder in my filesystem. I moved the SDK manager to a folder on my desktop, and installed updates through there. I had to change my android path to that folder, and everything fixed! Thanks for your help though, it was much appreciated.
I´ve recently imported a project I knew was working before into Eclipse. After I try to install the project it says
09-13 11:55:43.628: E/AndroidRuntime(7880): Caused by: java.lang.ClassNotFoundException: cz.ursimon.heureka.client.android.prj.heureka.activity.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/cz.ursimon.heureka.client.android-1/pkg.apk]
but I can´t find out what the problem is. First I thought it is the common problem with new ADT update, but I tried checking the PrivateLibraries in Order and Export according to other solutions, I cleaned my project several times and I can´t see anything wrong in my AndroidManifest file.
Anyone with a solution? :S
My AndroidManifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.ursimon.heureka.client.android"
android:installLocation="preferExternal"
android:versionCode="26062"
android:versionName="3.0"
>
<activity
android:name=".prj.heureka.activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using.
Clean all projects afterwards and Run your project
In your manifest file define the whole class path of your activity as below for your activity.
Also make sure your package defined is correct and in that pacakge your MainAcivity class resides.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.ursimon.heureka.client.android"
android:installLocation="preferExternal"
android:versionCode="26062"
android:versionName="3.0"
>
<activity
android:name="cz.ursimon.heureka.client.android.prj.heureka.activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
</manifest>
I got an ClassNotFoundException with a static broadcastreceiver. The exception is fired when installing the app via eclipse on the device. I am developing an sony smartwatch extension, so I need to use the "SmartExtensionUtils" project from the sony sdk. As long as I was working inside the code example project everything was fine. I started a new project with Maven + Android and now it is no longer working!!! No idea why?!? I reckon something with the packages went wrong....
I got the following error:
E/AndroidRuntime(11201): java.lang.RuntimeException: Unable to instantiate receiver com.bla.move.smartwatch.sony.ExtensionReceiver: java.lang.ClassNotFoundException: com.bla.move.smartwatch.sony.ExtensionReceiver
My broadcastreceiver class is called ExtensionReceiver. The name inside the manifest file is the same ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bla.move.smartwatch.sony"
android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="7"/>
<uses-permission
android:name="com.sonyericsson.extras.liveware.aef.EXTENSION_PERMISSION" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="SmartWatchPreferenceActivity" android:label="#string/preference_activity_title">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name=".SmartWatchExtensionService" />
<receiver android:name=".ExtensionReceiver">
<intent-filter>
.....
</intent-filter>
</receiver>
....
What could be the problem? Any suggestions??? I did alreday clean + rebuild (a couple of times)!
Did you include the SmartExtensionAPI and SmartExtensionUtil projects as dependencies, both in your project and in Maven?
Try cleaning the workspace (start Eclipse with the -clean flag), and make sure your project's JDK compliance settings is set to 1.6 (not 1.7)! That worked for me. I set the JDK compliance level of the whole workspace, instead of the project itself, and the error just disappeared!