This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

importing a package  RSS feed

 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have created a class called MessageGenerator in package message. and imported the MessageGenerator to a class called TestMessage.

I got the output in Eclipse,but when I do the same this in TEXTPAD I am getting an error as :cannot find symbol
symbol : class MessageGenerator
location: package message
import message.MessageGenerator;

The below code is what I wrote in a textpad :



----------------------------------------------------------------------------

Am I wrong at line 1,2,3?
Please tell how should I mention the package name and import a class to another class.
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure your class MessageGenerator is named MessageGenerator.java and is in a folder named message in your classpath (or compiling folder).

In your class TestMessage file, simply place "import message.MessageGenerator" at the top, no package declaration necessary.
 
Yevgeniy Treyvus
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because both of the classes are in the same package, you don't need to import. So you can safely take out line 3.

My guess is that the reason the MessageGenerator class cannot be found is because you didn't compile it -- Eclipse automatically compiles things for you, Textpad doesn't.

So, when compiling (using javac) are you sure you're compiling *all* the classes and not just the Tester class that has the main?
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I removed line 2 I am getting an error as :
package message does not exist
import message.MessageGenerator;

How can I set package in textpad.

I complied both the classes.
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heyyyyyyyyyyyyy I got ittttttttt..........
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should post what your problem ended up being.
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class path was not set correctly.
Thank you.


I have one more question

Q : Convert a feet variable of type Test. For example ,6002 feet is converted to 2feet,240 yards,1mile.



I am not sure how to go about . Can anyone please explain me how go with the convertYards() method.SO tht the value passed is converted to yards.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!