Netbeans says newly created file already exists, file is blank - netbeans

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.

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"

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} {
}

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'

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

Related

Failed to create the part's controls in Eclipse with Salesforce

I have Eclipse Juno and Force.com IDE. When I try to create new classes they always show: failed to create the part's controls. It worked for the first time, but now they always show this. Same happens if I create them inside the force.com platform.
Error details:
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
etc ...
I would appreciate all help.
I had the same error. I fixed it by switching the eclipse workspace. Go to menu File->Switch Workspace->Other, and then select the same workspace you were working with. Eclipse will restart and you should not get the error.
I faced the same issue my default editor for JSP was Web page editor. Which I changed to JSP editor and everything is fine.
PS: To change to JSP editor
Right click on JSP page -->open with jsp .
I got the "failed to create the part's controls" error one day when I opened Eclipse and tried to view a java file I had been working on. When I opened the file I needed, it showed a red X and NullPointerException instead of the code. The error log mentioned "event loop exception" for some reason.
I restarted Eclipse, and the error was still there. I cleaned the project, updated the project, deleted and re-imported the project, deleted and re-imported the file, and the error still was there. As a last resort, I restarted Eclipse again and then the file was fine. So one of the clean/update/delete/import steps worked but I don't know which one.
Use eclipse -clean from command prompt to solve this problem.
I solved my problem like this:
This problem occur because of in eclipse default editor is not able to identify extension of that file. If you right click on file and open it with respective text editor ,problem will be solved
In ecllipse, every file types has some associated default formats and one of the default format set to the particular file type.
You can see this in General -> Editors -> File Associations-
This issue generally occurs when we open any file in the format which is not the default format of the particular types.
I got same issue when I opened one of the Java file in text format in ecllipse and then I started getting the same issue. After research, I observed that AspectJ/Java Editor was setting as default. After reset it to Java Editor, the problem got resolved.
Steps :
1. General -> Editors -> File Associations-
2. Select the content type and choose the default format for it.
3. Restart the ecllipse.
In general, it is some default file format that set in ecllipse causing the same issue.
in my case problem was that the server was resin and I didn't have the resin server extension installed
I solved the problem.
(1)Open the filed with TXT.
(2)Search and Delete the underline between number like:
int a = 10_000;
It works when i compile and run as others used, but it will fail if i save and open again.
I also had for the same problem and fixed it by updating eclipse. Help > Check for Updates.
This worked for me---->
Right click on pom.xml-->open with-->xml editor
Had a similar stacktrace on failed to create the part's controls while trying to open Git repositories view in Git perspective.
My case (cause) is different since I was migrating an Eclipse workspace from an Ubuntu VM to Windows.
Many thing were copied like projects, .git folders, or also .metadata Eclipse folder.
Tried with no success:
uninstall all egit component (installation details, then, install new software
restart eclipse -clean
reset Git repository perspective
I searched and found this invalid UNIX : separator in .metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.egit.core.prefs file.
GitRepositoriesView.GitDirectories=/path1/.git\:/path2/.git
Here, the : is invalid path separator on Windows.
I simply removed the value in this line, saved file, and restarted Eclipse:
GitRepositoriesView.GitDirectories=
(alternative: if needed, try to migrate those linux paths to their Windows equivalent too)
Git repositories view is back.

Why do eclipse error dissappear when I copy paste code to new file

I've recently had to move my code from one pc to another (oddly enough a windows terminal to a linux desktop).
fortunately (at least I thought) I had regularly exported the code using the export function in eclipse, and saved the copy onto a USB key.
So I simply 'imported' the code I had on the key into a new workspace on my new desktop. Things seemed happy and jolly. Obviously I needed to fix a few issues with paths and locations of libraries I had used, and make minor updates to some ant files. Nothing to major.
After having done all this I expected the various build path errors that I was getting would be resolved. Unfortunately not.
After much messing around with the various build paths of the files that where causing me grief I decided I would try to simple copy and paste the code in the files into a new class.
So I renamed the original class (appending _old to the name using eclipses refactor process). I created a new java class file, then copy / pasted the code frome the _old file to the new one, obviously I altered the name of the class and the constructor on the way.
The new files throw out no build path error, or anything else that concerns me (I still have some unused imports, but I will tidy these up when my development has finished for these libraries)
My question is, is this a problem with Eclipse (I'm still using indigo as I found juno very slow?), and if so, how can I troubleshoot to create a sensible bug report?
Or is it something else that I did wrong in my export / import ?
Thanks in advance for any comments.
David.
Don't know what went wrong because you obviously executed a lot of manual steps in between "then" and "now". A few hints though:
You can export/import all workspace preferences if you like (File -> Export -> General/Preferences).
You know about Project -> Build Automatically or Project -> Clean?
You can eliminate unused imports automatically through project or workspace preferences -> Java Editor -> Save Actions

Eclipse working set is missing

My Eclipse crashed, and a working set which I'd just spent an hour setting up is now missing.
But when I try and create a new working set with the same name, it says "A working set with that name already exists."
So if it exists, where is it? I can't find it in my workspace...
If it doesn't exist, why can't I create a new one of the same name?
I've tried refreshing my workspace (F5), and running ./eclipse -clean - no joy.
A little hack solved it :)
(Eclipse Java EE IDE for Web Developers, Version: Indigo Service Release 1)
Choose a project, right click on it.
Assign Working Sets...
In Working Set Assignments window: uncheck the checkbox called "Show only Package Explorer working sets" ... and voila: there is the disappeared working set.
Check that working set and Click "OK" -> Working set will appear in Package Explorer.
Another possibility is to click the arrow pointing down (View Menu), select top level element and then choose Working sets.
Neither of the above answers worked for me on STS 3.4.2. I kept getting the error "workspace of that name already exists" when I tried to create a specific name although I could not see it in the package viewer.
I found this file that contains references to the named workspaces:
<workspace dir>/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml
I noticed that the missing workspace had a
editPageId=org.springframework.ide.eclipse.ui.springWorkingSetPage
whereas the ones I could see were:
editPageId=org.eclipse.jdt.ui.JavaWorkingSetPage
So, my 'missing' working set would only show up in the spring package viewer. User error - but eclipse did not help find it...
At this point one can either rename/delete the spring workspace, then add it to the package workspace.
In my case I had to:
Right click on a project > "Assign Working Sets..."
"Configure Package Explorer working sets..."
Select the missing working sets and click OK
Et voilĂ !
I solved my problem by closing then reopening Navigator view.
Thanks all for the hints.
While they didn't exactly work as it did for some of you, here's what worked for me (using Eclipse Juno):
File -> Import -> Existing Projects into Workspace -> Select the directory from where to import your project(s) -> Finish.
Not sure what the specific cause was, though it happened when my machine crashed.

gwt-dev-mac.jar is missing?

I'm trying to use IntelliJ IDEA for GWT development on Mac OS X, and checked out a project from subversion a coworker created on Windows. The Project file came with paths to GWT ("C:..."), which obviously don't work for me.
When I change the GWT facet path in the Module Settings dialog it complains that the directory i've chosen isn't a valid GWT SDK folder because it's missing gwt-dev-mac.jar
But I can't find such a file anywhere on my machine.
When I rename "gwt-dev.jar" to "gwt-dev-mac.jar" and try to run the project, I get the error: "Unknown argument: -style" when it tries to run GWTShell.
I read this link, but I'm not sure what to do about it: http://youtrack.jetbrains.net/issue/IDEA-26017
What's going on here?
I'm dumb... when I updated IntelliJ I dragged the new application into my applications folder and assumed it would replace the old one.
It appeared with the typical greyed-out look because I hadn't started it yet... so I was still using IntelliJ 8.something. and not noticing.
Problem solved with version 9 with the addition of the "Fix" and "Create Artifact" features that appear where the error used to.

Eclipse autocomplete not working in some Java files

I have noticed that autocomplete is not working in some of java files in Eclipse.
Also, the files where autocomplete is not working, display a hollow "J" as the icon for the Java file. The files where autocomplete is working, icon for java file is a filled "J"
I am wondering if someone can point out what went wrong all of suddent, why the change in icons and why autocomplete and syntax highlighting is turned-off in the files with a hollow "J" icon?
Thanks.
update
Basically, I was doing what VonC has suggested but Eclipse was not refreshing that it why I was thinking that VonC's suggestion isn't working, after doing a refresh, the problem resolved.
Since this question is highly ranked on Google, I will add a solution to fix general auto complete issue, not for 'hollow J' ones.
Try Window (Windows/Linux) or Eclipse (OS X) -> Preferences -> Java -> Editor -> Content Assist -> Restore Defaults
also
Content Assist -> Advanced -> Restore Defaults
some answers (restore defaults) above do not work for some adt bundle installs as of jan '13.
in those cases, go to
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
and tick on the JAVA PROPOSAL options.
In this following picture, MyClass.java has a hollow J, because it is explicitly excluded from the sources to build:
Could you go to the properties of the project, "Java Build Path" Section, "Source" tab and see if some exclusion filter has been set ?
It is usual for instance to define:
**/Test*.java
to exclude at first building any unit-test class (when you have a large set of sources and do not want to be presented with Test classes during auto-completion, or do not want them considered during source searches).
Those with a hollow J aren't part of the build path of the project, so they can't participate in the normal build process and therefore auto-complete won't be enabled for these files (and other Java editor features!). You must add the folders with the Java files to be built to the build path using the 'source path' section of the project properties. This can be accessed by right clicking on a project in the project navigator / package explorer and going to Properties. See http://www.informit.com/articles/article.aspx?p=367962 for details.
Additionally, if the files aren't part of a Java project in the first place, you must create a project and move the files in, or put the files in an existing one. Again, make sure these file are under a source directory as described by that section of the project properties.
(source: teradata.com)
I cope with the issue by deleting the file if autocomplete does not work. Just before copying the source code. Then I have recreated the java file with the same name. Pasted the source code previously copied.
As an addendum to the #VonC answer, make sure that the Java files are part of the Inclusion pattern. I had a case where a build process was creating the project while only including .js files and not the Java files:
You can manually edit the inclusions via the Edit button. In my case, a fix was made to the build script to make it permanent.
Neither Restoring Defaults or my build path (file was already in package directory w/other files where auto-complete was working) fixed problem. Fix for me was to close the file explicitly (right click on file name in tab) and re-open. Interestingly, just re-starting Eclipse didn't work either.
Make sure you have the right directory structure. I believe that:
Hollow J icon beside Java file - will not be build
Normal J icon beside Java file - is a file to be build.
I made a mistake when I created webapp artefact. By default it does not create folder for Java, but for resources. I mistakenly put my sources there.
Have a look - see the difference.
I was able to get this fixed in Visual Studio Code, VSCode but entering crtl-shift-p and typing in clean. When I did that I ran the "Java: Clean Java Language Sever Workspace" command. This fixed my autocomplete issue for me.