Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 12:31 AM
Member
 
Join Date: Jul 2007
Posts: 40
baltimore is on a distinguished road
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
Hi, I'm sure this is really simple, I can't figure out why this is happening. First, the code.

Code:
public abstract class BusinessObject { public Vector validationMessage; protected HashMap data = new HashMap(); public HashMap read () { return data; } }
Code:
public abstract class Person extends BusinessObject { public Person() { } public Person (String nameString) { String newLast = ""; String newFirst = ""; if ( nameString.indexOf(",") != -1 ) { newLast = nameString.substring( 0, nameString.indexOf(",") ); newFirst = nameString.substring( nameString.indexOf(",") + 1, nameString.length() ); } else if ( nameString.indexOf(" " ) != -1 ) { newFirst = nameString.substring( 0, nameString.indexOf(" ") ); newLast = nameString.substring( nameString.indexOf(" ") + 1, nameString.length() ); } Person(newLast, newFirst); } public Person (String newNameLast, String newNameFirst) { data.put("nameLast", newNameLast); data.put("nameFirst", newNameFirst); } }
When I try to compile Person.java, the compiler tells me that at the line Person(newLast, newFirst); inside the Person (String nameString) constructor, it 'cannot resolve symbol' on Person (java.lang.String, java.lang.String). I've moved the last Person constructor above the others, between the others, etc., but I know that shouldn't make a difference.
I've tried casting newLast = (String) nameString.substring(... and that doesn't work.
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 09:45 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The way to call another constructor is with the "this" keyword. And it must be the first line in the constructor. I don't see any clean way of doing it here. You'll have to add the two strings to the map in this single–argument constructor.
Code:
public Person (String nameString) { this(string1, string2); ... }
I came up with this but it's a little bizarre. Had to get rid of the abstract modifier to use it. Compiles and runs.
Code:
import java.util.*; public class PersonTest { public static void main(String[] args) { Person john = new Person("Lucas,John"); System.out.println("john = " + john); } } class Person extends BusinessObject { public Person() { } public Person (String newNameLast, String newNameFirst) { data.put("nameLast", newNameLast); data.put("nameFirst", newNameFirst); } public Person (String nameString) { this(Person.breakUp(nameString)); } private Person(String[] names) { this(names[0], names[1]); } private static String[] breakUp(String nameString) { String newLast = ""; String newFirst = ""; if ( nameString.indexOf(",") != -1 ) { newLast = nameString.substring( 0, nameString.indexOf(",") ); newFirst = nameString.substring( nameString.indexOf(",") + 1, nameString.length() ); } else if ( nameString.indexOf(" " ) != -1 ) { newFirst = nameString.substring( 0, nameString.indexOf(" ") ); newLast = nameString.substring( nameString.indexOf(" ") + 1, nameString.length() ); } return new String[] { newLast, newFirst }; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-18-2008, 09:30 AM
Member
 
Join Date: Sep 2008
Posts: 10
dhnsekaran is on a distinguished road
am also in same situation
kindly guide me
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
<variable>(Java.lang.string) in <classname> cannot be applies to () inksmithy New To Java 5 01-14-2008 12:36 AM
Error: cannot be applied to (java.lang.String) carl New To Java 1 08-05-2007 08:33 AM
Cast Error Caught (change) Class is really: java.lang.String barney Advanced Java 1 08-02-2007 06:07 PM
Error: java.lang.ArrayIndexOutOfBoundsException fernando Java 2D 1 08-01-2007 01:47 AM
Can't convert java.lang.String to int. Albert AWT / Swing 2 07-13-2007 07:05 PM


All times are GMT +3. The time now is 11:34 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org