• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

I saw a tutorial, Eclipse offers him more imports than me, why?

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, good day, I was imitating the tutorial and I found that this happens with the Date type class. How can I solve this problem? Eclipse has been failing me for months, thanks.
I can't update eclipse either, by clicking on that option. Why? Thank you.
MI-ECLIPSE-POCAS-OPCIONES.png
Mine Eclipse
Mine Eclipse
POCAS-OPCIONES-ECLIPSE.png
His eclipse
His eclipse
 
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how it is not working for you.

When I create a class similar to yours, and hover the cursor over the Date type in the constructor, I am presented with a list of fixes, which includes adding an import for various types.




When I (left) click the java.util.Date option, an import for that type gets added to the class file.




Is this not the same for you?


I am using Eclipse IDE for Enterprise Java and Web Developers version 2023-12 (4.30.0)
 
Saloon Keeper
Posts: 28321
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand the question.

When you click the "error" icon at the left bar and get presented with the popup list of fixes, the possible fixes suggested are built based on Eclipse' view of your development environment. Your environment isn't necessarily going to be the same as someone else's, since it's made from detectable resources in your system, and that can include stuff like Maven repositories, other workspace projects, environment settings, JDK selected and so forth.

With luck, you'll see the solution you need in that list, and all you need to is select it from the menu. Eclipse will then attempt to resolve the error based on your selection.
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the thread title, Bruno Valdeolmillos wrote:I saw a tutorial, Eclipse offers him more imports than me, why?


Oh - I didn't pay attention to the title - you are asking why does the IDE in the tutorial show more import options than yours (or mine).

The import options  presented are based on the classes  with a matching name found in the classpath/modulepath.

To demonstrate, if I create a new class named Date and put it in separate package so that an import is required, you can see that it will now show-up as an import option.



It looks like in the tutorial, the presenter's project includes Date classes from the sun.util.calender.BaseCalendar and sun.util.calender.LocalGregorianCalendar packages, so they show up in their list of import options.
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:I'm not sure how it is not working for you.

When I create a class similar to yours, and hover the cursor over the Date type in the constructor, I am presented with a list of fixes, which includes adding an import for various types.




When I (left) click the java.util.Date option, an import for that type gets added to the class file.




Is this not the same for you?


I am using Eclipse IDE for Enterprise Java and Web Developers version 2023-12 (4.30.0)


I have the same version as you.
And it offers you and option plus 12 and to me 11.
I wonder if it has something to do with the JDK?
They recommended that I touch something in preferences and now 14 solution options appear
My main question is why there is so much difference between possible solutions to that error, in this case 13.
It makes me think that my jdk, or something is incomplete or poorly configured (because I have had many problems with Eclipse for a long time)
It is not bad practice to create a class with the name Date?thank you
 
Sheriff
Posts: 28329
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:I have the same version as you.

But Ron's point is that your classpath doesn't contain all of the classes named "Date" that his classpath does, or that the tutorial guy's does.

I wonder if it has something to do with the JDK?

No, it's the classpath.

It is not bad practice to create a class with the name Date?thank you

Not especially. I suppose if you have a class which represents a date you might want to consider just using Java's built-in Date class, but you could have reasons not to do that.
 
Bruno Valdeolmillos
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Bruno Valdeolmillos wrote:I have the same version as you.

But Ron's point is that your classpath doesn't contain all of the classes named "Date" that his classpath does, or that the tutorial guy's does.

I wonder if it has something to do with the JDK?

No, it's the classpath.

It is not bad practice to create a class with the name Date?thank you

Not especially. I suppose if you have a class which represents a date you might want to consider just using Java's built-in Date class, but you could have reasons not to do that.


And for what reasons does my classpath not have all the Date classes?
 
Paul Clapham
Sheriff
Posts: 28329
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bruno Valdeolmillos wrote:And for what reasons does my classpath not have all the Date classes?


Because you haven't downloaded them from wherever that other guy downloaded them from and put them into your classpath.

Not that you should, of course. The other guy wanted them for some reason unknown to us. If you want them then by all means go and find them. But they aren't part of the JVM so you shouldn't expect to find them in your classpath.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic