Android Studio 3.0.1无法创建Java类问题求助
Fixing "Cannot resolve template 'Class'" Error in Android Studio 3.0.1
Hey there, let's break down how to fix this frustrating issue, plus address your temporary workaround question.
First: Fix the File Header Template Syntax Error
The second error you mentioned (about the File Header.java template at line 2, position 40) is almost certainly the root cause of the "Cannot resolve template 'Class'" problem. Here's how to fix it:
- Open Android Studio's Settings (go to
File > Settingsor pressCtrl+Alt+Son Windows/Linux,Cmd+,on Mac). - Navigate to Editor > File and Code Templates.
- Switch to the Includes tab, then select the
File Headeritem. - Check the content in the editor pane—you'll likely find a syntax mistake in the comment (like a misplaced
)or incorrect closing comment tag). Replace it with a standard Java file header format, for example:/* * Copyright (c) ${YEAR} ${USER}. All rights reserved. */ - Click Apply then OK, then try creating a new Java class again.
If That Doesn't Work: Reset All File Templates
If the header fix doesn't resolve the issue, resetting all templates to defaults should help:
- In the File and Code Templates window, click the gear icon in the top-right corner.
- Select
Restore Defaultsand confirm the action. - Restart Android Studio, then test creating a new class.
Still Stuck? Clean Up Corrupted Configuration Files
Reinstalling Android Studio sometimes leaves behind corrupted configuration files. Here's how to clear them:
- Close Android Studio completely.
- Locate the AS 3.0.1 configuration directory:
- Windows:
C:\Users\<YourUsername>\.AndroidStudio3.0 - Mac:
~/Library/Application Support/AndroidStudio3.0 - Linux:
~/.AndroidStudio3.0
- Windows:
- Delete this directory, then restart Android Studio—it will regenerate fresh default configurations.
Your Temporary Workaround: Valid and Functional!
Yes, using the Java class generated by a blank Activity is a great temporary fix. Here's how to adapt it:
- Create a new blank Activity as usual (this will generate a Java class and XML layout).
- Open the generated Activity class, then strip out the Activity-specific code (like
extends AppCompatActivity, theonCreatemethod, etc.). - Rewrite it to match your desired class structure, for example:
public class YourCustomClass { // Add your class logic here } - You can also delete the auto-generated XML layout file if you don't need it.
内容的提问来源于stack exchange,提问作者user9134466
相关产品推荐
相关产品推荐

