class files created in intelliJ only showing as decompiled and file not writable
Answered
Hi,
When I create a new empty class file in intelliJ it only showing as decompiled and the file is not writable.
So if in IntelliJ I create a new class called `Cat` and it should pre-populates it with a basic class structure and be writable.
Showing something like this :
//Cat.java
class Cat{
}
But that doesn't happen.
I'm using IntelliJ IDEA Community Edition 2018.1.2 x64
Any ideas why?
Thanks,
Rob
Please sign in to leave a comment.
How do you create the class file? Note that it should have .java extension.
Check the file types, make sure .java extension is mapped correctly to Java Source:
Hi, thanks for the reply.
I did this
Expand main folder
Right click on java folder.
New > Java Class
named it Cat
and selected Java Class as the file type
Try to delete IDE configuration to start with the defaults (https://intellij-support.jetbrains.com/hc/articles/206544519). Something is wrong with the settings/file types.
Hi, thanks for the reply.
So delete the config file completely?
at C:\Users\(user_name)\.IdeaIC2018.1\config
Yes.
okay I've done that and when I've tried to start the program I now get this message
https://gyazo.com/6c13ad0259d4058f57768a8fbf443ee3
so what do I do now?
It is asking me to complete the installation from the choice of 2 options
Custom location, Config folder or installation home of the previous version
or
do not import settings
Do not import.
okay I've done that
But when I make a new project in intellij with gradle I get a message saying "No Java SDK of appropriate version found. In addition to the IntelliJ Platform Plugin SDK, you need to define a JDK with the same Java version (JDK_1_8)"
What would do I do now?
Configure JDK, as usual: https://www.jetbrains.com/help/idea/creating-and-managing-projects.html#configure-jdk
okay I've done that I opened a new project and I'm trying to create a new java class file in the same way as before when I choose the file type I get a message box up saying https://gyazo.com/143944aeb53ced3e77ba521700ae6e9d
This happened before and I chose the accepted option
in case you cannot see the picture I link to it's asking about the jetbrains decompiler and the options are to accept, decline and restart or decide late.
Which option should I choose?
Please provide a video of how you create a Java file.
I don't know how to do that but I did exactly as I describe above.
i chose the decline and restart option this time from the decompiler message I gave a screenshot of and this time I chose the option of decline and restart. When I try to create a java class file the same thing happens as I described in my very first pos.
I don't know what to try next?
Here is how it works: https://i.imgur.com/uSLyNi6.gifv
Yeah that is exactly what I'm doing I get a different dialogue box that comes up though first I am asked for the name I click ok and then I am asked to select the file type and I select Java Class.
But instead of getting the result you have I still get the same result as my very first pos.
Any ideas what is happening?
You should select Java Source, not Java Class, see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000367870-class-files-created-in-intelliJ-only-showing-as-decompiled-and-file-not-writable?page=1#community_comment_360000166444.
I did that but I do not get the automatic
public Class Hello{
}
I just get a blank file.
Use https://getsharex.com/ to get a video and provide it. I don't understand what happens and why you get this behavior.
You said that you get a dialog asking for the file type after you click OK. On my video there is no such dialog.
If you get a dialog to select the file type, it means IDE doesn't know the type of the file already. You either specify some wrong name or you are using New | File instead of New | Java Class and specify some incorrect extension (or no extension at all). Make sure the file you create has .java extension (not .class) and .java extension is associated with Java Source file type as shown on the screenshot above.
New | Java Class action automatically creates a file with .java extension and you specify the class name only (without extension).
Note that Java Class files can be created only in the directories that are configured as Sources, see https://www.jetbrains.com/help/idea/configuring-content-roots.html.
In a directory that is not a Source root you will not have New | Java Class option. Only New | File.
.java — Java source file
.class — Compiled Java .class file (bytecode)
So, make sure you create New Class file (which is a ClassName.java file and not ClassName.class file) in the Source root (outlined with the blue color in the project view).
I will try that tomorrow but won't get a chance tonight.
Hi! I think I might have the same issue. My Main file is saved as a java file, and not a class file. For some reason. I'm trying to do a course on Pluralsight and followed the instructions, but the result differs. I.e. I get a main file in java format, while the teacher on the online course gets a .class file when doing the exact same thing. Strange. @Rob did you figure it out?
Please see https://stackoverflow.com/a/42660624/104891 and https://stackoverflow.com/a/43319356/104891 . You can also get the sample project and open it in IntelliJ IDEA to see what's the difference: https://stackoverflow.com/a/42200519/104891 .
Hi Serge Baranov, thanks for replying so quickly. I checked one of your threads and discovered an error, I had gone in to the src folder instead of out folder where the Main.class was saved. However now I get another error. Do you possibly have a quick fix for a n00b like me? :)
Please check my answer at https://stackoverflow.com/a/58125957/104891 .