Android studio gradle error with top-level exception-ThrowExceptions

Exception or error:

I have recently updated my Android Studio, since then my project does not build…I get errors like the error below:

        Error Code:
            1
        Output:
            UNEXPECTED TOP-LEVEL EXCEPTION:
            com.android.dx.cf.iface.ParseException: 
    class name (org/pervasivesystems/mobilehealth/activities/AppSettingsActivity$AppSettingsFragment)
 does not match path 
(org/pervasivesystems/mobilehealth/Activities/AppSettingsActivity$AppSettingsFragment.class)

I have many of these errors…I guess it has something to do with the capital letters? I wanted to know any possible soloution to this kind of error.

This is the full error report for one of the exceptions:

Error Code:
    1
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.cf.iface.ParseException: class name (org/pervasivesystems/mobilehealth/activities/AppSettingsActivity$AppSettingsFragment) does not match path (org/pervasivesystems/mobilehealth/Activities/AppSettingsActivity$AppSettingsFragment.class)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:520)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.processClass(Main.java:665)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
        at com.android.dx.command.dexer.Main.access$600(Main.java:78)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:596)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)
    ...while parsing org/pervasivesystems/mobilehealth/Activities/AppSettingsActivity$AppSettingsFragment.class

Everytime that Android Studio gets updated it messes my projects and I have to put tons of time to convert projects to be compatible with new versions!

How to solve:

I was able to fix this by clicking on the ToolBar item Build --> Clean Project. This fixed things fine. enter image description here

###

The names of your directories have to match exactly with the names of the packages declared in your manifest. So if you have:

com/SomeDirectory/package then your package in the manifest has to be:
package=”com.SomeDirectory.package”

In your case it looks like you’d called one “activities” and the other “Activities”.

###

I had the same problem. It’s interesting how a small thing like this can block you from building your app. The problem on my side was in AndroidManifest.xml file:

<manifest
    package="silviu.mypack"
    xmlns:android="http://schemas.android.com/apk/res/android">

Instead of “silviu.mypack” I had “silviu.mypackage”. I did a refactoring earlier and this didn’t change.

Good luck to everybody!

###

In my case I had an enum named CODES and an inner class called Codes. Apparently this causes trouble. Since Codes was the replacement for CODES I was easily able to fix it by removing all remaining references to the enum and finally by removing the enum having only on thing called codes in my class.

Leave a Reply

Your email address will not be published. Required fields are marked *