Unable to parse template "Class"

Viewed 76482

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?

16 Answers

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

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.

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

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

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

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

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.

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...

Related