• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java import not working in Package  RSS feed

 
Kamesh Sai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

I am trying to understand the package and import functions.

The path to access the file " library.book" is

C:\Users\Kamesh\Desktop\Java Session\JAVAOCA7\book\library

and i can see 3 txt files

Book.class
Book.ctxt
Book.java

while compiling i am getting <identifier>expected error.

Here is the code :

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37511
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The House class needs to be in its own file. You only get one package statement per file and it has to be on top before other statements.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't import paths in the form of strings, you should import types in the form of identifiers.

That means it should read import library.Book;, going by your package statements. However, if book is part of your package structure, then your package statement should be package book.library; and your import statement should be import book.library.Book;.
 
Kamesh Sai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Stephan van Hulst. Still getting error after i updated it as "library.Book;"

 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't really help you unless you tell us how you're compiling your code.
 
Kamesh Sai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you have asked which IDE am i using to complie the java code,

It is Blue J 3.1.4(Java Version 1.8.0_20)
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you stop using BlueJ and try the command line. When I suffered from BlueJ I found it handled package names badly.
See what happens and then tell us the error messages.
You do realise the package structure and the folder structure for .class files must correspond to each other? Have a look at the Java® Tutorials.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And upgrade to the latest version of Java® (8u45).
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is library.Book a file, a directory, a class?

Your earlier path is a bit confusing...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!