java.lang.RuntimeException: Unable to start activity....java.lang.ClassCastException: android.widget.RelativeLayout
I got this exception out of nowhere; this happens when I was actually trying to activate a new activity which, a second ago, ran fine. I tried everything, force stop the app, uninstall the app, restart eclipse, restart computer, none of which works. Then it occurred it me that there was a time when I fixed a problem like this by just closing the layout XML file and reopening it. So I tried that, and it didn't work. So I tried the one last thing: I copied out the layout XML file's content, deleted the XML file, and created another XML layout file with the same name, copied the stuff back in, and it worked! How could this be? Is it a bug of the eclipse plugin? It cost me 3 hours just to find this nonsense; I'm pissed.
I've seen that exception when I was editing some smali files and repackaging the apk. In those cases, the problem was that resources.arsc was zipped with compression instead of stored. Sometimes that messes up all the xml structure and android is unable to read it correctly. It could be some weird Eclipse bug when repackaging the apk, and it would not be the only one. From time to time, I get and error exclamation mark in one of the android projects, usually one that I did not touch in a while. I don't really know what triggers that, though.
I ran into this problem using both IntelliJ and Ant to build a package. It didn't matter if it was a debug version or signed release version both failed on startup. However, after running ant clean everything began working again.
Related
I have been using Android studio for a long time, yet never understood what are the processes that Android studio runs at when we load a new project via File>New or File>Open. We just load the project and have to wait for so many minutes before the android studio completes those processes (I know that we can still click on file names and editor would open them, but i have observed the android studio will still lag until all those processes are completed)
However I don't know how, recently My Android studio started behaving differently. I don't know what i did, But every time i created a new project, or loaded a previous one, it would show a message like this:
This was very good for me, because even when i don't click the try again
button, I am still able to access all files and without any lag, thereby removing a need for external file editor. I feel this was some bug in gradle or cache handling that got fixed when i uninstalled AS and updated to AS 3.5 .
So is there a way to manually run all those build and indexing processes, instead of Android Studio just running them automatically?
UPDATE:
I think i was not clear before. I want that error to occur . Meaning I want to have a control over when the building process starts. Also, I am NOT having any error as of now, all my projects are working fine.
Look for highlighted warnings in you Gradle file, you may need to update some things and then sync again.
You could also try to clean and rebuild your project.
You can also File->Invalidate Caches / Restart if none of the above work.
If none of the above work, please provide more details on what warnings/errors you get.
When version conflict in gradle file, it cant be able to build and sync the project.There may be show "Unsupported Modules Detected: Compilation is not supported for following modules”. Fix them too
I'm having an issue suddenly with the export process in Eclipse for licensing my Android app prior to release.
When I build normally under debug mode and deploy to the device, the file size is 11,782Mb. When I use the export process, the file is smaller, 11,322Mb. The file is corrupt and won't load when I test it on the device. When this process is successful, the file is the same size.
This happened once or twice before, and usually cleaning and rebuilding the project sorted it out, but now it's happening every time no matter what I do. Any ideas what is happening here please?
Edit: Production key is fine, use it all the time.
When I attempt to install the app, I get ClassNotFoundException:
java.lang.RuntimeException: Unable to instantiate application com.myapp.android.App: java.lang.ClassNotFoundException: Didn't find class "com.myapp.android.App" on path: DexPathList[[zip file "/data/app/com.myapp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.myapp.app-1, /vendor/lib, /system/lib]]
There are several possible reasons for ClassNotFoundException that I have run into. Here are a few suggestions:
You mentioned "clean and rebuild" - for some reason (usually related to compiling the R.java file) I occasionally need to "clean" more than once for a good production build. I can even do a "clean" and export on a test that is fine, then do an export with a fail. I've probably done over 1000 deployments to Google Play across 50+ apps. It happens...
Android's Installer is corrupt. Yes - this happens, too. Sometimes with a production deployment (not with "debug" or "AVD" - but with "ADB" install or production installs) the Android installer will not ever install your app again. Factory reset of the device is the only solution. I believe an Android OS update can solve the problem, but I've only seen that work intermittently and haven't really tested it.
Manifest errors. Sometimes the production manifest file doesn't match the app classes. Usually this happens with a refactoring of class names. Eclipse in particular does not seem to always modify the manifest file properly. You may need to check it manually.
A res file changed. Sometimes when editing an XML document you will have an error that is not picked up by the compiler or IDE. You do a build and deploy to a test device that for some reason doesn't seem to use the resource or some other strange error. Usually it won't deploy anywhere properly, but I've seen it deploy to a test device and then not deploy in production. As a practice, I avoid this problem by occasionally "uninstalling" and then re-installing the app during testing.
The OP reminded me of another along the lines of the comment below (for future readers) - try deleting the generated files from the build. For example, anything in "BIN" and "GEN" can be deleted and re-built using "build." These files sometimes contain artifacts from previous builds that are no longer valid but are not detected during an automatic build process.
Those are some suggestions. Give them a try...
I recently updated to the most recent Android Studio version (0.2.x), and I am experiencing an issue where I cannot build the project. I receive an error message stating:
Gradle: Execution failed for task ':TestApplication:compileDebug'.
Compilation failed; see the compiler error output for details. C:\Users\user\AndroidStudioProjects\TestApplicationProject\TestApplication\build\source\r\debug\com\example\testapplication\R.java
Gradle: error: illegal unicode escape
Now, I understand I was supposed to reinstall Android Studio as per instructions:
Windows users: Do not install Android Studio 0.2.x in the same location as 0.1.x.
Doing so may cause errors such as ClassCastException or other unexpected behaviors.
It's best if you remove your previous version of Android Studio 0.1.x.
And I actually did, I uninstalled Android Studio, and deleted the remaining folder (Which is apparently not deleted after uninstall) stored at: C:\Users\user\AppData\Local\Android
I then proceeded to clean the registry entry just in case (I tried this on my 3rd attempt after not getting it to work), and rebooted before re-installing.
After the PC rebooted, I proceeded to do a fresh install of Android Studio, it installed successfully. I created a Test Project from scratch (to make sure it was not a problem with opening previous projects), but right after it opened the project it's already showing the build problems. I tried running it and it simply won't compile.
What's even more strange is that all of the problematic lines according to the compiler output are commented lines in the R.java. Here's one:
/** From: C:\Users\user\AndroidStudioProjects\TestApplicationProject\TestApplication\src\main\res\values\dimens.xml
And it points to the character 30 of that line, which is right between the u and the s of the word user (image attached). I actually tried deleting the comments, but as you'd expect the R.java was generated automatically when I asked for the project to be rebuilt.
I have absolutely no clue what the problem is, any ideas?
Known issue. We have fixed it internally already. Should have it out very soon (couple of days max)
I had the same problem and I was using a path similar to yours.
What I did was move the project to the root of the C drive, so the path doesn't start with "C:\Users\user" anymore and the problem is avoided... Not really a solution, but a workaround.
PS: This is not really an answer, but I don't have enough points to comment yet and this might help someone.
These are the errors that i am getting when i attempt to run my project. It was working perfectly fine till yesterday. I have no idea what is causing the error. I cleaned the project and reran a number of times. I even restarted my laptop, but in vain. Please help me restore this, its a very huge project.
My friends copied the project on his laptop and was able to run it successfully. Which concludes that there has been a problem with my eclipse.
There are too many errors to sort out. I would very much recommend the easy way out which is to uninstall Eclipse (in case it really is the source of the problem) re-install it and start up a new project, then slowly add in the project files one by one. At least this way if the error comes back you know which file it is (if any). Best of luck.
Try to update eclipse if there is any update to apply.
I'm developing an Android application on Eclipse Juno, and using a MAC OS Lion.
When I fix some error in a xml file the error mark doesn't disappear, and it doesn't let me compile the code even if I fix it. I tried deleting it through Window-> Show View -> Problems , but when i compile the code, the error came back. The only way i figured out to solve it is to crop all the content in the file, save the xml without errors and then paste the same code inside the xml file again, the error just go away as if there wasn't anything there.
Does anyone now why it happens?
Grahaminn is correct in that seeing the code would be helpful in case there is something that you are missing. However, since you say that it goes away once you cut, save, and paste, I believe you did take care of the error. While I've never found an answer to the same question other than the eclipse compiler obviously has bugs, I have had the same thing happen and have had to resolve the issue in the same way. The compiler, for whatever reason, still sees the error instead of the fix. It is very frustrating but we are stuck doing what you have done until the compiler is fixed.
Update your Android development tools. That bug (Android Lint issues remain even after correcting them) was fixed in ADT 20.0.2.
If you can't or don't want to upgrade, you have the options of
cleaning the project
manually running Android Lint again.
But similar errors will occur again from time to time then.
Thanks for all the answers. My Eclipse is working properly at least until now, the only thing with still giving me headaches is the R.java file which keep disappearing sometimes , but thats due to problems with ADT i guess. I uninstalled the ADT plugin and installed it again.