Android Studio crashes when I open xml file - android

Please help me solve the following bug. After many attempts, I came to the conclusion that the point is not which program template I am using, but specifically in the xml files that have a design section (like activity_main.xml), it seems to me that I have already re-tried everything:
installed new gradle
deleted the .idea .gradle folders, files with the .iml extension, modules, settings.gradle files a million times
Invalidate Caches / Restart
changed the path for the SDK
imported the project using "Import project (Eclipse ADT, Gradle, etc.)"
deleted all files along this path C: \ Users (Your UserName). AndroidStudio (version) and not only these files
did chkdsk
And it still doesn't work. The crash occurs only when opening xml files with design sections, on other files, including .xml, everything is ok. Has anyone come across a similar one?
P.S. the error occurs by default along with the creation of a new template.

I seem to have figured out this error.
For those who will come across something similar in the future:
If I start a project and open an xml file that has a design in it (for example, activity_main.xml), then the program crashes. If you do not open this file, then everything is ok. You can even run it. The solution is as follows: you need to go to your project, while the main thing is that the xml files (similar to those I described above) are closed. Then start the MainActivity class with a debugger (set a breakpoint and then shift + F9) and then you need to walk a little (I mean step into with debugger) (maybe this is not necessary at all) through the files using F7 (step by step) and then open the file activity_main.xml (or any similar ) and voila! It will load and will not kick you out. Then you can work. You can even go out and go into the project and then it shouldn't crash anymore, but after the reboot your system you will need to repeat this process. I don’t know what it’s connected with at all, but it seems to me that the problem is that something prevents the .xml files (that is, the design tab) from loading and the program starts to crash with an unknown exception. And in order to solve this, you need to somehow run this file.

Try to install the latest Android Studio version from here and reinstall all files from beginning on your set-up

Restore default settings
I think its work.

I've solved the issue by installing Android Studio 4.2 RC 1 from https://developer.android.com/studio/archive.

Related

Why does Android Studio use the old source location when a project has been moved?

I have a Kotlin-based Android Studio project located at C:\DEV\PROJECT1 which works fine. I copied the project SOURCE to C:\DEV\PROJECT2 and loaded it into Android Studio.
All of my classes as well as my namespace have a red underline under their names in the Project panel to the left and each editor tab. The IDE thinks there are duplicate classes because it's still referencing the source code in the OLD directory.
When I debug, the IDE says there are multiple versions of a class and at the top of the editor window you can choose from either directory.
This is causing a huge problem for me for multiple reasons, so I'd like to get the IDE to forget about the old directory when loading the new copy of the project.
I've tried all the tricks I found on the Internet but none of them work. I've manually deleted the "caches" directory in C:\Users\me\AppData\Local\Google... I've done the same thing within the IDE with File->Invalidate Caches. I've manually deleted the .gradle and .idea directories, as well as all build directories.
I had a friend load the project SOURCE on his computer the same as I've done above, and he experiences the same issue. So I don't believe it's an environment issue.
Does anyone know what's going on here and how to fix it?
Thanks.
None of the other answers mentioned worked for me. What I had to do was change the value of 'rootProject.name' in settings.gradle. Until I did this, it would always remember the old directory where the project used to be and would always use source from that directory.
This makes no sense to me so I'm going bo post another question to see if someone can explain why Android Studio NEVER forgets the location of a project name. I can't imagine anyone ever wanting that behavior.

Android Studio project doesn't recognize some classes

Recently my project got messed up. I don't know how it became like this. There was no power failure or anything happened while using Android Studio. Next day I opened my project and now it's a full mess. I attached the images of how they look now.
Classes are not recognized as you can see they have .java extension showing and when I opened one of them it show like below. but if I opened the file directly from notepad or something the source-code of these files are not changed.
I did delete .idea all .iml files inside the project then invalidate & restart build project again. But no luck, no matter what I did it doesn't get resolved. I have an old backup of this project and not a recent one, so I want to get this fixed .
I tried opening my other projects and they work very well. The problem seems to be only in this project. Android Studio is updated to last version before this problem persisted. So it's not also a bug in Android Studio.
This is how the Java file looks when I opened with Notepad++. The code didn't disappear, no I also didn't write xml code in my Java file:
I just had to copy all the source code in .java files back into android studio editor, which the files are with .java extension. Problem solved
I have same problem occur few days ago, solved by below steps
uninstall android studio,
download latest from link
delete all file from default android studio folder
(C:\Program Files\Android\Android Studio)
install new downloaded android studio , all worked well.
I had a similar problem, but with Kotlin files.
What worked for me was shortening the file name by a few characters (but not the class name).
I suspect that there's a limit to the length of the path which can get quite long if you try to organise a large(ish) project using subfolders.
If you have just created a new package directory inside your project and moved class files from the project into the package directory you just created you will get this error.
To avoid it. Instead of moving class files, copy them and next build your project. Very important this part to build the project.
Next you need to delete the duplicate class files outside the package (Can't use safe delete for this)
And finally you need to change the imports on all affected class files to reflect the new namespace / location. My suggestion is to use "replace in path" from the Menu Edit > Find

Why can't I hit the breakpoint when I start debug the Xamarin Android Application?

When I start to debug my first Xamarin Android application, I set some breakpoints. Whatever I do, it will still not hit the breakpoint. What's wrong with this?
I have tried many times, but it did not help.
I've found that the name of the folder that contains your project can make a difference. Do you have any spaces or punctuation characters in yours?
The folder name is often the same as the project name, but it doesn't have to be. I had a Xamarin Android project called "Engagement (Android)" within a solution, and by default it was stored on disk at ...\Engagement (Android)\Engagement (Android).csproj
No matter what I did, it wouldn't hit breakpoints. Brand new projects that I added (called Test1, Test2, etc) - debugged perfectly.
When I changed the folder name to "Engagement_Android" (keeping the same project name) - it started hitting breakpoints again.
Other symptoms that went with this included the "Clean Project" option not clearing all the files from the bin/debug folder (it left behind the project's main DLL and PDB file).
The thing that nailed it for me was noticing that when I did a clean build, the bin/debug folder did not contain an "MDB" file for the main exe (in this case Engagement Android.dll.mdb) and so was not been packaged into APK file.
It turns out that the MDB files are the way that debugging information gets packaged up into the APK - without it you can't debug! I think they are created by a tool called PDB2MDB.exe during the build process.
If you try this, bear in mind it is the physical folder name not the project name that is important. Also, you need to edit the SLN file because it contains a reference to the path of each project in the solution - so make the change there too.
I experienced the same issue before and, I've managed to find a workaround for this. I have tried cleaning all of my project’s bin\Debug folders manually and this worked. Just never rely on the clean solution/project alone because this doesn't delete all the files in your output folders. After, rebuild your projects.
Also, try save all your work and shut down Xamarin Studio and restart it.
I have had a few issues in the past that only disappeared when I restarted the IDE.

R.java disappeared

I recently downloaded the Android Support Package and have been using it trying to get my application, running at SDK 10, to use a GridLayout.
Anyway, I cleaned my project a few times working on this error in my XML files, and then when I went back to my classes in /src, every single reference to R.* was an error.
This has happened to me before, but it usually fixes itself, and it has not yet. Does anyone know what to do?
The R.java file is no longer in my /gen folder.
It sometimes happens when you import another project First i suggest you to build it, it will create automatically .
If it's not working then try to create new project from existing source and specify the downloaded project . It worked for me
Hope this works for you let me know..
Sometimes if there is an error in your XML files R.java won't build. Go through your XML files to make sure that everything is in order (typo, forgetting to close a bracket, etc). When you fix that it should build itself again.
You can also try Adnroid Tools>Fix Project. That may help you to create gen/R.java file
Follow following steps :
In Eclipse,
=> Right Click on Project > Android Tools > Fix Project
By this way, you can fix many common problems which can help generate R.java in gen/R.java file.
There can be several reasons why this occurs. The following I have found happen to me and I have included the steps I took to resolve them.
First step is to try and clean the project (from the Project menu option I believe)
Check there are no errors with your XML files. Sometimes this is obvious from the red 'x' that appears next to an XML filename in the Project exlporer window and sometimes it is not. If it is not obvious check the 'Errors' window (whic is founf in the 'Windows' Menu option
Failing that I have found that by disabling the automatic build option, adding some arbitrary comment to an arbitrary source file, saving the source file, clean the project, remove the comment and then re-selcting automatic build can work too.
Apologies for the approximate locations for some of the Eclipse functions but I am not currently in front of Eclipse to check.
This happens when you have an error in the res folder.
Fix the error first, then do :
Project --> Clean --> Ok
Et voila !

Error showing on every project in Eclipse and I haven't changed anything

I have just opened Eclipse as I need to make some changes in an existing project. I added a new file to my 'Raw' folder and refreshed the folder and when I went to build it shows a error 'x' on the project but not against any of the source files, etc. It also shows an error against every other project in Eclipse even though I haven't touched any of them
If anyone has come accross this problem before please let me know how I can rectify it.
I have several times problems with Eclipse highlighting everything with errors even when everything is fine.
Sometimes it looks like Eclipse caches the errors and does not clear them properly.
In those cases, I tried different things such as:
removed the file you just added. Refresh and clean the project and see if it has fixed it.
Remove project from Eclipse and import it again.
Close Eclipse and open it again.
For me, the above sometimes work.
The issue might with unresolved build resources. like some previously used path might not be available now. You can goto the properties of the project and check in the respective tabs if some of the paths earlier set are not valid anymore.
I've managed to resolve the problem. You need to delete the debug.keynote file in .android which had expired! Then clean and rebuild your app and the debug.keynote file will be recreated and the error removed.

Categories

Resources