Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

why doesnt package work but import does  RSS feed

 
Ranch Hand
Posts: 339
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using intelij

on the left i have my project and two packages under that

how come my video tutorial types package *package name* and then is able to access the classes in that package

but if i go package package name im just getting red underlined "class or interface expected"

i can however import and it works...is there a difference between importing and using the package keyword

thanks
 
Marshal
Posts: 5941
412
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest I didn't quite catch.

Could you please show an example of code maybe?
 
Liutauras Vilda
Marshal
Posts: 5941
412
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beside that, I have a feeling that your package statement weren't first statement in your source code - but it should.
 
jon ninpoja
Ranch Hand
Posts: 339
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
jon ninpoja
Ranch Hand
Posts: 339
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package testpackage is in red,the testpackage package is under the package that this class is in
 
jon ninpoja
Ranch Hand
Posts: 339
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to upload a screen shot on this site?
 
Rancher
Posts: 3604
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have one package declaration.
 
Dave Tolls
Rancher
Posts: 3604
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jon ninpoja wrote:package testpackage is in red,the testpackage package is under the package that this class is in


Also, if I have understood this correctly, testpackage should be the package that TestMain is in, nit a package underneath that.
 
Sheriff
Posts: 5037
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jon ninpoja wrote:is there a way to upload a screen shot on this site?


In general, we like to see the text of code and error messages, but yes, you can upload an image by pressing the Attachments tab (upload local or URL), or embed an image using the Img button (URL only).
 
jon ninpoja
Ranch Hand
Posts: 339
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
screen shots of intelij
Screenshot-from-2018-02-28-16-06-22.png
[Thumbnail for Screenshot-from-2018-02-28-16-06-22.png]
 
author
Sheriff
Posts: 23571
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As already mentioned, the package statement should be the first line (except for comments), and you can only have one package statement.

Having two package statements isn't valid Java. What exactly are you expecting to happen with two statements?

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!