Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java codes are converted to XML after restarting Android studio

I faced a real strange scenario when after I restarted my PC due to freezing of windows some of my java codes in the Android Studio were converted to some strange xml codes and all those codes I written were lost! I faced this situation twice, the first time I faced this scenario, I reverted my code to last commit since the changes were very little after the last commit. However this time the changes are huge after the last commit and I am completely perplexed!

The below is how one of my small code was converted.

<component name="libraryTable">
  <library name="Gradle: com.android.support:print:28.0.0@aar">
    <ANNOTATIONS>
      <root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/print-28.0.0.aar/87cddf7f66cc3e6d635cf04e7292a008/annotations.zip!/" />
    </ANNOTATIONS>
    <CLASSES>
      <root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/print-28.0.0.aar/87cddf7f66cc3e6d635cf04e7292a008/res" />
      <root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/print-28.0.0.aar/87cddf7f66cc3e6d635cf04e7292a008/jars/classes.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</component>  

My Android Studio version: 3.3.1

Is there any way to get back the code I wrote?

Any help would be appreciated.

EDIT

I faced again the same situation. Here is one of my another code replaced with xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="AndroidConfiguredLogFilters">
    <filters>
      <filter>
        <option name="logLevel" value="verbose" />
        <option name="logMessagePattern" value="" />
        <option name="logTagPattern" value="(MainActivity|Download|BooksFrag|Reading|BookPage|BookDetails|PageNumberPicker)" />
        <option name="name" value="Unnamed-0" />
        <option name="packageNamePattern" value="" />
        <option name="pid" value="" />
      </filter>
    </filters>
  </component>
  <component name="AndroidLayouts">
    <shared>
      <config />
    </shared>
  </component>
  <component name="AndroidLogFilters">
    <option name="TOOL_WINDOW_CONFIGURED_FILTER" value="Unnamed-0" />
  </component>
  <component name="ChangeListManager">
    <list default="true" id="0218df07-b316-45c7-a2ad-66ba2c0b4c43" name="Default Changelist" comment="">
      <change afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/utilities/RealmDBHelper.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/BookSearchResultsContainer.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/BookSearchResultsContainer.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/BookSearcher.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/BookSearcher.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchOptions.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchOptions.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchResult.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchResult.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchResultViewHolder.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/SearchResultViewHolder.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/activities/ReadingActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/activities/ReadingActivity.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/utilities/ArabicUtilities.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/sed/maktaba_daar_al_hadeeth/utilities/ArabicUtilities.java" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/app/src/main/res/values/strings.xml" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/res/values/strings.xml" afterDir="false" />
    </list>
    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
    <option name="SHOW_DIALOG" value="false" />
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
    <option name="LAST_RESOLUTION" value="IGNORE" />
  </component>
  <component name="ExternalProjectsManager">
    <system id="GRADLE">
      <state>
        <projects_view />
      </state>
    </system>
  </component>
  <component name="FUSProjectUsageTrigger">
    <session id="1042793738">
      <usages-collector id="statistics.lifecycle.project">
        <counts>
          <entry key="project.closed" value="23" />
          <entry key="project.open.time.12" value="2" />
          <entry key="project.open.time.13" value="2" />
          <entry key="project.open.time.14" value="1" />
          <entry key="project.open.time.15" value="3" />
          <entry key="project.open.time.16" value="1" />
          <entry key="project.open.time.17" value="1" />
          <entry key="project.open.time.18" value="2" />
          <entry key="project.open.time.2" value="1" />
          <entry key="project.open.time.21" value="1" />
          <entry key="project.open.time.22" value="1" />
          <entry key="project.open.time.24" value="1" />
          <entry key="project.open.time.25" value="2" />
          <entry key="project.open.time.26" value="2" />
          <entry key="project.open.time.27" value="5" />
          <entry key="project.open.time.28" value="1" />
          <entry key="project.open.time.29" value="1" />
          <entry key="project.open.time.3" value="1" />
          <entry key="project.open.time.30" value="1" />
          <entry key="project.open.time.31" value="1" />
          <entry key="project.open.time.32" value="1" />
          <entry key="project.open.time.36" value="1" />
          <entry key="project.open.time.4" value="1" />
          <entry key="project.open.time.46" value="1" />
          <entry key="project.open.time.49" value="1" />
          <entry key="project.open.time.5" value="2" />
          <entry key="project.open.time.50" value="1" />
          <entry key="project.open.time.51" value="1" />
          <entry key="project.open.time.6" value="2" />
          <entry key="project.open.time.7" value="1" />
          <entry key="project.open.time.8" value="2" />
          <entry key="project.opened" value="44" />
        </counts>
      </usages-collector>
      <usages-collector id="statistics.file.extensions.open">
        <counts>
          <entry key="MF" value="1" />
          <entry key="css" value="4" />
          <entry key="csv" value="11" />
          <entry key="gradle" value="14" />
          <entry key="java" value="298" />
          <entry key="js" value="19" />

I logged an issue with Google here.

Thanks.

EDIT (Nov 2019)

I faced this in android studio 3.5.2 as well. It seems the issue is not fixed yet.

like image 715
itabdullah Avatar asked Mar 02 '19 12:03

itabdullah


People also ask

Why does Android still use XML?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy.

What is the purpose of .Java and .XML in Android Studio?

Android uses xml to declare layouts and java to provide logic.

Can we use HTML instead of XML in Android Studio?

yes it is possible you can design whole page in html and stored in Asset folder with image used,css,script folder,and in android activity you just open it in webView . Show activity on this post. Show activity on this post.

Can Java program be run on Android Studio?

Android Studio can now build Java modules and run them in the local JRE.


Video Answer


1 Answers

dont worry!

Go to android studio folder located in Users/user/.androidstudiov.x.x And delete your cache and restart android studio. This problem happened to me a couple of days ago, right after I upgraded to the new version. Even XML and java classes will have this. However all your data is safe. A bug in android studio, importing settings..

like image 84
0xA Avatar answered Oct 17 '22 11:10

0xA