Cannot Find Symbol Constructor Error In Java
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company
Cannot Find Symbol Error In Java Compile
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs cannot find symbol error in java interface Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, constructor cannot find symbol java just like you, helping each other. Join them; it only takes a minute: Sign up Inheritance in Java - “Cannot find symbol constructor” up vote 10 down vote favorite 3 I'm working on a class that inherits
Java Constructor Example
from another class, but I'm getting a compiler error saying "Cannot find symbol constructor Account()". Basically what I'm trying to do is make a class InvestmentAccount which extends from Account - Account is meant to hold a balance with methods for withdrawing/depositing money and InvestmentAccount is similar, but the balance is stored in shares with a share price determining how many shares are deposited or withdrawn given a particular amount of money. Here's the first
Constructor In Java
few lines (around where the compiler pointed out the problem) of the subclass InvestmentAccount: public class InvestmentAccount extends Account { protected int sharePrice; protected int numShares; private Person customer; public InvestmentAccount(Person customer, int sharePrice) { this.customer = customer; sharePrice = sharePrice; } // etc... The Person class is held in another file (Person.java). Now here's the first few lines of the superclass Account: public class Account { private Person customer; protected int balanceInPence; public Account(Person customer) { this.customer = customer; balanceInPence = 0; } // etc... Is there any reason why the compiler isn't just reading the symbol constructor for Account from the Account class? Or do I need to define a new constructor for Account within InvestmentAccount, which tells it to inherit everything? Thanks java inheritance polymorphism share|improve this question edited Feb 7 '13 at 10:48 charles 4,95824286 asked Feb 4 '09 at 10:19 benwad 2,70253570 add a comment| 5 Answers 5 active oldest votes up vote 24 down vote accepted use super(customer) in InvestmentAccounts constructor. Java can not know how to call the only constructor Account has, because it's not an empty constructor. You can omit super() only if your base class has an empty constuctor. Change public InvestmentAccount(Person customer, int sharePrice) { this.customer = customer; sharePrice = sharePrice; } to public InvestmentAccount(Person customer, int sharePrice) { super(customer); sha
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community http://stackoverflow.com/questions/510784/inheritance-in-java-cannot-find-symbol-constructor Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Cannot find symbol symbol : constructor …” in Java? up vote 3 down vote favorite I have a class defined as follows... public class df { String http://stackoverflow.com/questions/10200034/cannot-find-symbol-symbol-constructor-in-java dt; String datestring; public String df(String dtstring) throws Exception { dt=dtstring; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date inpdate = formatter.parse(dt); datestring = formatter.format(inpdate); Date outpdate = formatter.parse(datestring); SimpleDateFormat newformatter = new SimpleDateFormat("dd/MM/yyyy"); datestring = newformatter.format(outpdate); return datestring; } } I create instances of this class as follows, where rsnpos.getString(1) contains a date in yyyy-MM-dd format (e.g. 2010-01-01)... new df(rsnpos.getString(1)) During compilation, I am getting the following error... cannot find symbol symbol : constructor df(java.lang.String) location: class df I don't understand why this is happening, as I have defined a constructor as shown in my code. Could someone please assist me with this problem. java constructor syntax-error share|improve this question edited Apr 18 '12 at 2:54 WATTO Studios 7,216103045 asked Apr 17 '12 at 22:19 ARNAB2012 13712 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted That's not a constructor... (constructors have an implicit "return type",
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of http://stackoverflow.com/questions/9321547/java-cannot-find-symbol-constructor this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign cannot find up Java: cannot find symbol (constructor) up vote 2 down vote favorite newbie doing Java homework here. I have one class named Album which contains the following constructors: public class Album { private String title; private String artist; private String genre; private Song favoriteTrack; private int trackNumber; private static int numAlbums; //Constructors public Album(String title, Song favoriteTrack, int trackNumber) { this.title = title; cannot find symbol this.favoriteTrack = favoriteTrack; this.trackNumber = trackNumber; artist = favoriteTrack.getArtist(); genre = favoriteTrack.getGenre(); numAlbums++; } public Album(String title, Song favoriteTrack) { this(title, favoriteTrack, 1); } ...} And then I have a second class MusicCollection which instantiates the Album class thrice, within its main method... public static void main (String[] args) {... Album album1 = new Album("Debut", "Venus as a Boy", 3); Album album2 = new Album("Homework", "Around the World", 7); Album album3 = new Album("Ghost in the Machine", "Invisible Sun", 3); ...} However, when I attempt to compile MusicCollection.java, I get the error: cannot find symbol symbol : constructor Album(java.lang.String,java.lang.String,int) location : class Album for each time I try to call the constructor. The classes Album and MusicCollection ARE in the same directory, and Album.java compiles. I imagine I'm doing something silly, but I can't figure this out. Any help would be much appreciated! java constructor compiler-errors share|improve this question edited Feb 17 '12 at 1:10 Jivings 16.3k43172 asked Feb 17 '12 at 1:07 Christina Kirkman 1815 Asking for homework help is fine, but remember to include the homework tag. –Jivings Feb 17 '12 at 1: