not possible to make normal package in eclipse - java

In Eclipse I have two projects with the same package structure.
In one of them by mistake i delete the package.
When i Want to make structure I lost again I see this:
not this :
what is wrong ?

Make sure the folder is in your build path.
Try right clicking it and choose "Build Path" > "Include".

You may be browsing in the Navigator view, not the Package Explorer view.

Related

Intellij right-click 'New' is not showing 'Class'

Related: IntelliJ does not show 'Class' when we right click and select 'New'
In the above accepted answer, it says the "New" does not give the option for Java Class because it was not the source root (blue directory).
However, as you can see, even though where I am right-clicking is source root, indicated by blue box, it is not giving me the option for Java Class
Any idea why?
This directory is imported from git so it did not follow the usual "Create Project" for java directly from Intellij
You are right clicking in the wrong spot -- youre "too high" up the tree. Go to where you code is (as in the package under "src") and try it there and you will see the option for a New Class.
EDIT: You don't need to be in the source root. You need to be in the source directories themselves. The blue dot I believe is a git status indicator. What you want is an entirely blue folder.
Go down under "src". Likely under "src" then "main" then "java", and you're there (that's blue for me) and then you will see your package folders. Below those are where you likely want to be adding classes.
As many mentioned above you can right click on the folder you would like it in. In your case:
If you push Alt+1, it might be easier for you to right click
src > New Java Class
Alternatively you can push:
Alt+1 (Project View)
Alt+Ins
or
Ctrl+Alt+Ins
1) Right click on src
2) Click New > package
3) Name your package and press OK
4) Right click the newly made package
5) New > Java Class
If the folder where we are trying to create the class is not marked as source or test then the option is not available.
Right click the project and go to project structure then under project settings -> Modules, Select the folder where you wanted to create class and mark as Source or Test appropriately and then click apply and ok.
Now you will see the change of color of the folder/package(Sources->Blue, Test->Green) and you will get the option to create the class.
This worked for me.
I know this is an old thread, but it happened to me because my gradle files were not synchronized. So if you are within a team working on same project and face this issue, make sure to run gradle sync.
You should go inside java project then you can create java class.

Eclipse showing java project src folder view as all packages and subpackages

Not sure how to really ask this question since I don't know what everything is called but I'll try to do the best I can.
So as I was cleaning up my classes. I right clicked my project and selected refresh. Then all of a sudden my project view changed, the src folder shows everything as packages and '.' separated subpackages. And all my code package declarations seems now to be undiscoverable.
I've attached a photo, hopefully you can petter understand this...How can I fix this to have the correct directory view/structure.
Edit:
Here is what I have linked to my JAVA build path
I don't understand what is happening? How can all of a sudden my project screw up like it has? Any help will be much appreciated
Look at the 'Java Build Path' in the project 'Properties' and check that you have the correct 'Source' folders. It looks like you may have just 'src' as a source folder when you should have 'src/main/java', 'src/test/java'...
I was able to fix this by maven>update project, then just refresh...
In addition to the previous answer you also may use empty package filter:
At the top-right of the Package Explorer view, there's a downward-pointing triangle. If you hover your mouse pointer over it you'll see View Menu.
Click the View Menu, select Filters, put a check next to Empty Packages, then click OK.
Same way you could tune other options for Package explorer such as file types to show etc.
Well, it seems pretty clear that your hierarchy does not match the name of your package, so just fix your hierarchy. It will be easier if you switch to the hierarchical view of the packages. To do so, go to Package explorer, View menu (arrow icon pointing to the bottom), Package presentation, Hierarchical.
The following worked for me:
Right Click on src (which is shown like empty package in my project) -> Build Path -> Use As Source Folder

Why isn't intellij giving me the option to create new classes?

Here's what I'm seeing:
Normally I can choose "New Java Class" but for some reason I'm not getting this option. I created this project by opening an empty directory and building it out from there. I've seen this question, but that answer didn't help me. Here's my module settings:
Even if I open my pom.xml directly as a project, it still has this problem. How do I fix 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.
For some reason, intellij didn't recognize my directories as packages. If I created something directly from the java directory, it would give me the correct options. I fixed this by deleting everything under java/ and recreating it. This may be an intellij bug.
This happened when I was trying to add classes to a generated package using xjc plugin.
Intellij allows to add classes only to packages which are correctly names and have the "source root" status.
Can be fixed as-> right click on the directory where you're not able to add classes:
Mark sources root
refer image for clarity
This worked for me :
Right click the java folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
Right click the myproject folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
So basically had to mark some inner folder as Source project and alter mark parent project again as Source project..
Hacky way but this worked for me.

No Package Hierarchy Importing Project in Eclipse

I've been trying to import a project that works on a friend's computer, however no matter what I try, the package hierarchy is completely lost and the result is this
Has anyone seen this issue before? I've been struggling with it for a while. Occasionally creating a new project and copying in the src folder works, but I've been unsuccesfful in my recent attempts.
The presentation of packages is a user option. Click the little down-arrow at the top of the package panel, then select "Package Presentation" from flat to hierarchical.
Turns out we weren't including the .classpath file in the source control. Facepalm. Good answers, though.
It could also be that the folders are not listed in the project as Source Folders. Go to the project properties and check that the root folders (looks like "data" and "src" here) are listed as source folders in the Build Path.

Eclipse: don't notice Error when import fail Class

This below image is my eclipse of my two different projects. And each black rectangle is a package in folder src of Eclipse project. As you know, there a different point: The icon of each package is different.
1) first project: package has normal icon. (like java package)
2) second project: OPPS !!! It displays a folder.
And, the problem that I want to tell is: in project 1, when I type something wrong, eclipse has notice errors. For example: I declare: Example() example = new Example();
But at project 2, Eclipse cannot. That you have seen on my screen: Eclipse eclipse = new Eclipse();
Obvious, when compiled, It failed.
I think that I might do something wrong, and I just a newcomer to Eclipse, and really don't understand much this IDE.
Please help me for my problem.
thanks so much :)
As I think, because you have imported "your package" just by move your source. there are two ways (with my knowledge) that might work:
1) Like Baldrick does.
2) go to Properties\Java Build Path\Projects: add a project that contain package you want to add. this will make two project a linker. when you compile this project, this will also compile project that you link to.
Right now the second (lower) project doesn't have the source directory set up as a source directory, so it isn't trying to compile it. No compilation, no errors. Update your project settings by right-clicking and adding the source directory to the source paths.
Right click on your projects, go to "Properties" and "Java Build Path". In the "source" tab, add your folder src to the list of source folders.
Looks like you've created a New Folder in your project AndroidGame whereas you created New Package in your other project (can't see name).
You should create a new package in your AndroidGame source folder and "Refactor->Move" your source to it.
As an Eclipse newbie question, you should always Create Package (File -> New -> Package) when creating a package. Folders tend to be required for web content, images, resources (say for property files to be added in your target classpath), etc.

Categories