user1533320
user1533320

Reputation:

Netbeans says newly created file already exists, file is blank

Ok, so, using Netbeans for a small Java project. Anyway, it was working fine this morning. Then, after working on another project briefly and switching back, something changed.

Now, when I create new .java files, it says they already exist - but, they didn't, until then. That is, the filename didn't exist, and once I made it, it said it already exists, which, after it says that, it does. Which, well, the file didn't exist before, so it is a problem.

Secondly, the file it creates is blank. It is much easier to use when it creates it using the template: automatically adding the package statement, and class structure.

This persists across a restart.

Sounds similar to this: Netbeans creates file, then complains it already exists

On Windows 7. Netbeans version 7.3

Any ideas how to fix?

EDIT:

I think I may have found the cause. I had changed the default class template, or more accurately, took a few sections out of the default. Apparently the second time I did it, I also erased a bit of the template markup, and it was this syntax error that ended up making this happen. After fixing the syntax error, it seems to work.

Upvotes: 8

Views: 4915

Answers (4)

Justin Huber
Justin Huber

Reputation: 1

I had this issue and none of the previous stated solutions worked for me. I found that simply copying the created file directory i.e C:\Users\Bill\Desktop\randomjavafile.java and deleting the file and then trying again works :).

Upvotes: 0

Lakshan
Lakshan

Reputation: 31

I had the same issue once. I used Netbeans IDE 8.2v with a dedicated Java pack pre-installed. Even after reinstallation, this error couldn't be fixed for me. In a previous Netbeans version, I changed the template forms according to my way - this was the cause of the file/class already existing error for me. After another reinstallation process, I manually reverted all changed templates to the application default way. You can do it out & fixed this error. It worked for me!

PATH : Netbeans >> Tools >> Templates >> a single click on Java folder >... to your right-hand side there's a button pannel >... click on 'Revert to Default'

Upvotes: 0

Tushar KhaN
Tushar KhaN

Reputation: 1

The solution is go to Tools -> Templates -> expand Java folder -> select "Java Class" -> open in editor

use this code in java class file

<#if package?? && package != "">

package ${package};

public class ${name} {

}

Upvotes: 0

Magnus
Magnus

Reputation: 41

I had similar experience: Every time I right clicked in Netbeans 8 to get a new Class in a package I only got a empty file and a complaint about that the file already exist.

The solution was for me to go to Tools -> Templates -> expand Java folder -> select "Java Class" -> press "Revert to Default"

Upvotes: 4

Related Questions