Problem with IntelliJ -> Cannot create class with name "Main" - java

Title states my problem, i get this error message:
Cannot Create Class Unable to parse template "Class"
Error message:
Selected class file name 'Main.java' mapped to not java file type
'Files supported via TextMate bundles'
Anyone got any ideas on how I can solve this?

Please check the File Types. It looks like Main.java file name or extension was mapped to the wrong file type by accident (Files supported via TextMate bundles). Remove the invalid type mapping to fix the problem. The name/extension should be mapped to Java files instead (the default setting).
See if disabling TextMate bundles plug-in helps.

You do not need "Edit" button at all. Instead you need to use "-" (Minus) button in Registered Patterns area:
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )

Related

Is there a way to tell intelij to ignore a file inside a package

I file inside a package and I want intelij to ignore it. every time I ran my code intelij keeps showing me errors and info from that java file. Is there any way for me to make intelij to ignore that file
Right click on the file > Override File Type > Plain Text
Note: This action DOES NOT override the file type of a specific extension. Instead, it override the file type of a specific file
You may switch-off all error highlighting at the top right corner for this file:

How to solve java file mapped to not java file type text

I wanted to add a java class to a project, but I did a mistake and added it as a text file. Then, I removed it and tried to add it again as a java class, but unfortunately it doesn't work anymore. And I get the following error:
Unable to parse template "Class" Error message: ABC.java mapped to not java file type text
As I searched, I faced some solutions like
this one but I can't find File Type under Editor or anything similar that I can change as suggested in the solution.
Any help would be appreciated.
PS: I am using IntelliJ 2018.3.4.
Thanks in advance,
Go on File->Settings and a dialog will open. In that dialog navigate on the left part to Editor/File Types and then you need to choose from the section Recognized File Types Java Class and remove from bottom section the problematic extension (note you have a small minus button on the right)
https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html
This is a variant of Markov's answer that worked in my scenario.
Try going to File->Settings->Editor->File Types and to the Recognized File Types tab. Click the "Auto-detect file type by content" choice, and delete the name of the file you are trying to create from the "File Name Patterns" section by using the minus button.
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )
Certainly inelegant, but you can simply copy the contents of the file to the clipboard (ctrl-c or similar), delete the file (maybe make a temporary backup somewhere outside the project), then in IntelliJ go to the desired package, right click, select new, select Java Class, name it correctly, and then you can paste in the contents of your file (ctrl-v or similar).

using doxygen for java with Doxywizard

Doxywizard Doxygen not scanning the packages for java files
Need help on Doxygen/Doxywizard
These are my Doxywizard settings:
Working directory from where doxygen will run:
C:/Program Files/doxygen
In 'Wizard' tab, the below values are set.
Source code directory:
C:/workspace/git/employeeapp/src/main/java
Destination directory:
C:/Doxy-docs/1
In 'Expert' tab, under Topics-'Build' , selected the 'EXTRACT_ALL'
I installed Doxywizard, open the wizard, set the above values, went to 'Run' tab
and clicked 'Run doxygen', I expected that all the folders/packages inside the 'src/main/java'
will be scanned and a project default documentation would be created.
Problem: However I see that 'C:/Doxy-docs/1/html/index.html' is blank and no other pages were created.
If I just navigate to a folder where there is a '.java' file [say src/main/java/com/app/], documentation is created for
the '.java' files inside that folder. But as in the above scenario where 'src/main/java' is mentioned,
the tool is not scanning for packages/folders inside for the '*.java' files.
Question: Am I missing some configuration? or is this the expected functionality of doxygen that it cannot scan inside
folder-folder etc?
Note: This link shows the features of doxygen and from that I think it support the feature that I am expecting.
http://www.doxygen.nl/features.html
Note: I added java tag only because I am using the wizard to scan java files
I continued my effort in finding the option to set it,
and came across this link,
http://www.ibm.com/developerworks/aix/library/au-learningdoxygen/
which mention about 'RECURSIVE'
: Set this tag to Yes if the source hierarchy is nested and you need to generate documentation for C/C++
files at all hierarchy levels. For example, consider the root-level source hierarchy /home/user1/project/kernel,
which has multiple sub-directories such as /home/user1/project/kernel/vmm and /home/user1/project/kernel/asm.
If this tag is set to Yes, doxygen recursively traverses the hierarchy, extracting information.
Got my boy - its 'RECURSIVE'
In Doxywizard, found it under 'Expert' tab and then Topics - 'Input'
checked the checkbox against 'RECURSIVE', and selected '*.java' in FILE_PATTERNS.
Executed again, and the whole documentation is on the table!!! [destination dir what i mentioned]
or,
In the 'Expert' tab itself, when we specify the 'Source code directory',
there is a checkbox for 'Scan recursively'. Just check it.

IntelliJ does not show 'Class' when we right click and select 'New'

We're creating a new project in IntelliJ and must have something wrong because when we right click on a directory, select New and then get the context menu, Java based options are not shown. Currently get things like File, some HTML options, XML options.
We have assumed so far it's something we haven't configured correctly in the Project/Module configuration. The new module we are talking about is part of a multi module project. We created it using a Maven web archetype.
Any help configuring the project nature?
Edit: The answer is basic: 'That moment when you realise somethings not working because you haven't been clicking 'Apply'... :) We had a good laugh at ourselves when we discovered this'
The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).
If this is not the case, right click your root source directory -> Mark As -> Source Root.
This can also happen if your package name is invalid.
For example, if your "package" is com.my-company (which is not a valid Java package name due to the dash), IntelliJ will prevent you from creating a Java Class in that package.
you need to mark your directory as source root (right click on the parent directory)
and then compile the plugin (it is important )
as result you will be able to add classes and more
If you open your module settings (F4) you can nominate which paths contain 'source'. Intellij will then mark these directories in blue and allow you to add classes etc.
In a similar fashion you can highlight test directories for unit tests.
Project Structure->Modules->{Your Module}->Sources->{Click the folder named java in src/main}->click the blue button which img is a blue folder,then you should see the right box contains new item(Source Folders).All be done;
I will share another interesting point. If you try to create a package with the reserved keyword then it will be treated as a normal directory and not a package. I was having this issue where I was creating a package named import and it was converting that to a directory.
Another possible solution is that the project name is not acceptable. For example, creating a project with spaces in the name does not block the project creation but the proper sources are not marked and when those are marked manually, I still was unable to create classes. Recreating the project with hyphens (-) instead of spaces corrected the problem for me.
Make sure you are not creating a package name which is same as predefined keywords in java like enum, int, long etc.
In my case I was trying to create a class under "enum" package. As soon as I changed package name to "enums" I was able to create class in it.
Had this issue too. Invalidating Caches/Restart did the trick for me. Please upvote so the the IntelliJ folks take this more seriously. This gives the IDE a terrible UI/UX experience.
https://youtrack.jetbrains.com/issue/IDEA-203100
There is another case where 'Java Class' don't show, maybe some reserved words exist in the package name, for example:
com.liuyong.package.case
com.liuyong.import.package
It's the same reason as #kuporific 's answer: the package name is invalid.
If you just created your project, let IntelliJ finish indexing your project.
You need to mark your java directory as Source Root ,
Right Click on Java directory
Select Mark Directory as option and click on the sub menu option Source Root
Most of the people already gave the answer but this one is just for making someone's life easier.
TL;DR
You must add the test folder as source.
Right click on java directory under test
Mark it as Tests
Add src/test/java in Test Source Folders
Thats it, IntelliJ will consider them as test source.

NetBeans doesn't recognize ${project.organization} in license template

Can anybody reproduce the following?
In my NetBeans 7.2 project I've set the "project.license" property (in project.properties) to "apache20" so that NetBeans generates the appropriate license text in every new .java file. The license text (which is located in "license-apache20.txt") contains the following FreeMarker reference:
${project.organization!user}
When "project.organization" is not set it displays my user name as expected. Also, when I set a custom user name in the User.properties file it displays this user name instead. So far so good.
However, I want to set the "project.organization" property. But when I do this in the project.properties file NetBeans simply doesn't recognize it, displaying my user name instead.
When I remove "!user" from the FreeMarker reference it generates the text "Expression project.organization is undefined on line 4, column 59 in Templates/Licenses/license-apache20.txt." When I set the property in User.properties instead (silly place, but I did it for sake of analysis) I get the same behavior. Does anyone know what might be wrong or how to get NetBeans to find the "project.organization" property? Does anyone have the same behavior on his or her NetBeans?
In license-apache20.txt (or any other license template), change ${project.organization!user} to ${organization!user}
In NetBean menu, Tools ❯ Template, when you click the Setting button, a User.properties file is opened. Add organization=FooBar Inc there.
(This is not very ideal, but at least it allows to customize the organization.)

Categories

Resources