Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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
 
Sheriff
Posts: 5715
393
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
Sheriff
Posts: 5715
393
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: 3497
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have one package declaration.
 
Dave Tolls
Rancher
Posts: 3497
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: 4866
136
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: 23511
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
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!