'Unable to parse template "Class"

I am trying to create class in android but i got this error

Unable to parse template "Class" Error message: This template did not produce a Java class or an interface

and in Event log I got this error

FileNotFoundException: Entry fileTemplates//code/Google Test Fixture SetUp Method.cc.ft not found in /D:/Android%20Studio/lib/idea.jar

this my app bulid gradle

apply plugin: 'com.android.application'

android
  {

compileSdkVersion 23
buildToolsVersion '25.0.0'

defaultConfig {
    applicationId "com.hh.ss.msed"
    minSdkVersion 14
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.firebase:firebase-core:11.0.1'
    compile 'com.google.firebase:firebase-database:11.0.1'
    compile 'com.google.firebase:firebase-crash:11.0.1'
    compile 'com.google.firebase:firebase-storage:11.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.0'
    compile 'com.android.support:cardview-v7:23.0.0'
    compile 'com.firebaseui:firebase-ui-database:0.6.2'


    compile 'com.firebase:firebase-client-android:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:support-v4:23.0.0'


}


packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
   }
  }
  apply plugin: 'com.google.gms.google-services'

this bulid gradle project

// Top-level build file where you can add configuration options common to all sub-projects/modules.

  buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    classpath 'com.google.gms:google-services:3.1.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
 }

 allprojects {
  repositories {
    jcenter()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

what the wrong?



Solution 1:[1]

Go to File->setting->editor->file and code templates, select Class in the files tab and paste this:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public class ${NAME} { }

Screenshot of editor

Solution 2:[2]

I have the same problem, and got it solved by adding in the idea.vmoptions or idea64.vmoptions the following line:

-Djdk.util.zip.ensureTrailingSlash=false

as showed in JetBrains Support by user Wojciech Fred

Seems to be a fix applied by oracle to the Java 8 Update 144

I hope it helps :D

Edit: In Android Studio, the file is called studio.vmoptions, and can be found inside the configuration directory, but it is more easy if you go to the "help>Edit custom VM options" menu: Android Studio Configuration

Solution 3:[3]

I encountered something like this in android studio. What i did was I opened IntelliJ Idea (Since Android studio is based on it), and copied the default text of respective template and pasted in android studio respective file.

Go to File->setting->editor->file and code templates, select Class in the files tab and write this

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public class ${NAME} { } 

Solution 4:[4]

I didn't encounter this error before. I faced this issue only after I reinstall my android studio(version 3.0). Creating new Class give the following error as mentioned in the question.

Unable to parse template "Class" Error message: This template did not produce a Java class or an interface

So there are two ways to get rid of this error

Option 1 is @Semicolon answer

Go to File->Setting->Editor->File and Code Templates, select Class in the files tab and write this

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public class ${NAME} { }

Option 2 is @Angel Castelo answer

Add the following line to your VM custom option(studio.vmoptions).

-Djdk.util.zip.ensureTrailingSlash=false

My suggestion is to add it using android studio(Select Help->Edit Custom VM Options->then add the code). If you didn't create Custom VM Option File before then it will prompt a dialogue mentioning "Custom VM Option file not exist. do you want to create it" Select yes and the studio will create a Custom VM option file. Then follow the steps(above mentioned).

Conclusion

Which one is better?

When I first encounter this issue I choose option one and its worked well until I started my next project. When I started a new project the issue appear again so I visit this page and found option 2 and it worked perfectly for me.

When we follow option 2 creating new project doesn't trigger this issue again unlike option 1.

Further Reading

Intellij Support Page

Android Developer Page

Read more about Android Studio file templates

Solution 5:[5]

In your, IntelliJ IDE go to Help => Edit Custom VM Options and Add to your idea.vmoptions or idea64.vmoptions the following line:

-Djdk.util.zip.ensureTrailingSlash=false

You can read more about it here and here.

Solution 6:[6]

the trick by Semicolon works Similarly for adding interfaces go to

Android Studio -> Preferences -> File and Code Templates -> Files -> Interface

and add the following code

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public interface ${NAME} { }

Solution 7:[7]

This all answer may be right, and work very fine, I use this options for few days and it's work for me too, but there are one other option and i think which is much better because, this option is given by android developer which is as give as below:

For Class file template:

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

    #if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
    #end
    #parse("File Header.java")

    #if (${VISIBILITY} == "PUBLIC")public #end #if (${ABSTRACT} == "TRUE")abstract #end #if (${FINAL} == "TRUE")final #end class ${NAME} #if (${SUPERCLASS} != "")extends ${SUPERCLASS} #end #if (${INTERFACES} != "")implements ${INTERFACES} #end {
    }

Interface file template

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

#if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
#end
#parse("File Header.java")

#if (${VISIBILITY} == "PUBLIC")public #end enum ${NAME} #if (${INTERFACES} != "")implements ${INTERFACES} #end {
#end {
}

enter image description here

Solution 8:[8]

In my case it was working before but suddenly started to show this error message. I tried some of above answers but didn't help so clearing caches fixed my problem.

On Intellij Go to File > Invalidate caches/Restart and select Invalidate and Restart option.

Hope it helps.

enter image description here

Solution 9:[9]

The reason is you maybe installed the 64 bit version on a 32 bit machine. I had the same problem. If you have 32-bit OS, try to uninstall 64-bit version of Android Studio and install 32-bit version from this page: https://developer.android.com/studio/index.html#downloads

Solution 10:[10]

I'm on a Mac using IntelliJ IDEA 14 and I found the file idea.vmoptions here:

~/Applications/IntelliJ IDEA 14 (Right click Show Package Contents) /Contents/bin/idea.vmoptions

I then added the same line that the top answerer suggested:

-Djdk.util.zip.ensureTrailingSlash=false

Solution 11:[11]

I had occur same problem but I have fixed this problem by following steps:

Step 1: Go to File menu >> Setting

Step 2: then click on Editor and then File and code templates

Step 3: Now select Class

Step4 : After that paste this code in editor. For more details see the image.

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public class ${NAME} { }

enter image description here

Solution 12:[12]

Hi I had the same error and the error was due to a bad syntax in the Java File header template. I solved it in the following way:

Go to:

Android Studio -> Preferences -> File and Code Templates -> Includes -> File Header

If you have defined some variables in the template, check how the variables are defined, should be (for instance):

#set( $USER = "Your Name")

instead of

#set( USER  "Your Name")

I hope it helps

Solution 13:[13]

I had the same issue, it just appeared I didn't change any settings or update Android studio what so ever. I solved it by selecting

File -> Invalidate Caches & Restart

Solution 14:[14]

Go to File then setting -> editor -> file and code templates, select Class in the files tab and paste this " #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") public class ${NAME} { }" then click on Apply.

Solution 15:[15]

I found the same issue with my Idea 14. But when it was just installed it was not the case, later I found it appeared after protobuf plugin was installed. If you uninstall protobuf plugin it works again.

Maybe will help somebody...

Solution 16:[16]

If you, like me, tried everything to no avail, check if there's anything under Preferences -> Editor -> File Types -> File type auto-detected by file content and remove from there if it's the file name that is producing this error.

I have no idea how I managed to add the file name there, but it was there and was causing this error for me (it was working with other file names and only the one listed that got me that error).

enter image description here