Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2005

Tip: Looking for answers? Try searching our database.

Need some assistance

Thread view: 
aver24@hotmail.com - 10 Dec 2005 18:03 GMT
This is the error I get:
1 error found:
File: C:\JBuilder3\myprojects\PostCardDemo.java  [line: 9]
Error: cannot resolve symbol
symbol  : constructor PostCard (java.lang.String)
location: class PostCard

My teacher told me I didn't create the class, but I thought I did
'class PostCard'. Do I have to create an additional class? The last
lines of the program are commented out, but I assume that if I fix the
other errors that one will work too.

public class PostCardDemo {
 public static void main(String[]  args)  {
    String text = "\tI'm having a wonderful\n" +
               "time at Disney World. Weather's\n" +
               "great. Wish you were here!";
 PostCard p1 = new PostCard("Vanna", text);

 PostCard p2 = new PostCard(text);
 p2.setRecipient("Merv");
 System.out.println(p2.print());
 System.out.println(p1.print());

 p2.setRecipient("Mom");
 p2.print();

 PostCard p3 = new PostCard("Sweetie",
                            "\tI'm miserable without\n" +
                            "you. It's been raining all week.\n" +
                            "I can't wait to get back home.");
 p3.print();
 }

}

 class PostCard {
   public String recipient;
   public String content;

 public PostCard(String r, String t) {
   recipient = r;
   content = t;
   content = recipient + content;
 }

 public String print(){
   return content;
 }

 public String setRecipient(String n){
   recipient = n;
   return recipient;
 }

}

 //public String toString(){
   //return PostCard("[Dear " + recipient +"]");
 //}
pit.grinja@gmx.de - 10 Dec 2005 19:18 GMT
> This is the error I get:
... and it tells you everything you need to know...
> 1 error found:
> File: C:\JBuilder3\myprojects\PostCardDemo.java  [line: 9]
> Error: cannot resolve symbol
> symbol  : constructor PostCard (java.lang.String)
> location: class PostCard

Here you create a postcard via a constructor that accepts two "String"
parameters...
>   PostCard p1 = new PostCard("Vanna", text);
Here you create a postcard via a constructor that accepts ONE "String"
parameter...
>   PostCard p2 = new PostCard(text);
and here you again create a postcard via a constructor that accepts two
"String" parameters...

>   PostCard p3 = new PostCard("Sweetie",
>                              "\tI'm miserable without\n" +
>                              "you. It's been raining all week.\n" +
>                              "I can't wait to get back home.");
Lets look at your "PostCard" class
>   class PostCard {
>     public String recipient;
>     public String content;

Here is your "PostCard" constructor that accepots two strings...
>   public PostCard(String r, String t) {
>     recipient = r;
>     content = t;
>     content = recipient + content;
>   }
but where is the one that accepts only one string? That seems to be
missing, and java tells you that it cannot find a constructor with the
parameter signature that you use for "PostCard" p2.
HTH
Piet
Rhino - 10 Dec 2005 19:39 GMT
> This is the error I get:
> 1 error found:
[quoted text clipped - 56 lines]
>    //return PostCard("[Dear " + recipient +"]");
>  //}

If you look at the ninth line of your program, 'PostCard p2 = new
PostCard(text);', you'll see that it is trying to instantiate the PostCard
class with only a single String parameter. You don't have a constructor for
this class that expects a single String parameter.

You can resolve the problem in either of two ways:
- change the instantiation to pass two Strings; that will result in your
existing PostCard constructor being used
- create an additional constructor for the PostCard class that requires only
a single String parameter; in that case, the new constructor will be used.

Rhino


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.