• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

importing a package

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heyyyyyyyyyyyyy I got ittttttttt..........
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Your buns are mine! But you can have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic