Cannot Find Symbol Java Error Constructor
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 Business Learn more about hiring developers or java error cannot find symbol class posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss java error cannot find symbol method 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 java error cannot find symbol variable takes a minute: Sign up Java - Cannot find symbol constructor up vote 1 down vote favorite I'm completely new to Java, so I'm sorry if my question is dumb. Im working on this assignment, and I've been reading about main
Java Error Cannot Find Symbol Arraylist
methods for hours now, but I just cant figure it out. I put some of my code below. I might be way off here, but what I'm hoping to accomplish is to get the main method to start the constructor, but when I compile I get an error saying "cannot find symbol - constructor Player". Now, Im guessing this has something to do with the string parameters of the constructor, but I'm all out. If anyone could shed some light on java error cannot find symbol file this, probably very simple problem, I'd be very happy :) public class Player { private String nick; private String type; private int health; public static void main(String[] args) { Player player = new Player(); player.print(); } public Player(String nickName, String playerType) { nick = nickName; type = playerType; health = 100; System.out.println("Welcome " + nick +" the " + type + ". I hope you are ready for an adventure!"); } public void print() { System.out.println("Name: " + nick); System.out.println("Class: " + type); System.out.println("Remanining Health: " + health); } java methods constructor main share|improve this question asked Jan 31 '13 at 21:37 Jarand Boge 813 1 You're trying to create a Player, but you're not passing in a nickName or a playerType. –Louis Wasserman Jan 31 '13 at 21:38 add a comment| 5 Answers 5 active oldest votes up vote 2 down vote accepted Player has no default constructor, you could use: Player player = new Player("My Nickname", "Player Type"); Edit: If you wish to prompt the user for the Player arguments, you can read this like so: Scanner scanner = new Scanner(System.in); System.out.print("Enter Player Name:"); String nickName = scanner.nextLine(); System.out.print("Enter Player Type:"); String playerType = scanner.nextLine(); Player player = new Player(nickName, playerType); share|improve this answer edited Jan 31 '13 at 22:34 answered Jan 31 '13 at 21:39 Reimeus 122k9102164 What I want to do is make the program start, and then prompt the user for a nam
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the java error cannot find symbol ioexception workings and policies of this site About Us Learn more about Stack
Java Error Cannot Find Symbol Scanner
Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Error Cannot Find Symbol Javac
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 http://stackoverflow.com/questions/14635606/java-cannot-find-symbol-constructor 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 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 http://stackoverflow.com/questions/510784/inheritance-in-java-cannot-find-symbol-constructor - 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 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 qu
New Topic programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: Beginning Java java:12: cannot find symbol Niall Doyle Greenhorn Posts: 7 https://coderanch.com/t/454015/java/java/java-find-symbol posted 7 years ago Hi guys, Im new to programming in general...thanks in advance for your help: Im using jcreator to compile the following file (Employee.java which I have saved in C:\JavaPrograms): /** *This class contains basic employee info * */ public class Employee { String name; String role; int phonenumber; double salary; public static void main(String args[]) { Employee emp = new Employee("John Woo", "Java Programmer", 2125556347, 20000.00); //create an Employee cannot find object emp.printEmpInfo(); //print the Employee data } /*this method prints out all the employee's *details to the console */ } The errors I am getting are as follows: C:\JavaPrograms\Employee.java:12: cannot find symbol symbol : constructor Employee(java.lang.String,java.lang.String,int,double) location: class Employee Employee emp = new Employee("John Woo", "Java Programmer", 2125556347, 20000.00); ^ C:\JavaPrograms\Employee.java:14: cannot find symbol symbol : method printEmpInfo() location: class Employee emp.printEmpInfo(); When I run it, should it create an Employee.class cannot find symbol file in the same folder? Because this is not happening..any ideas? thanks! John de Michele Rancher Posts: 600 posted 7 years ago Niall, Welcome to JavaRanch! Your first error is pretty simple. You'll want to read up on constructors and object creation. The second error is also pretty obvious. Can you find a method called printEmpInfo() anywhere in your class definition? John. Niall Doyle Greenhorn Posts: 7 posted 7 years ago Hi John thanks a lot for your help so far... I read a bit about Constructors and I added in the line: public Employee() { in the class definition So heres what I have now: /** *This class contains basic employee info * */ public class Employee { String name; String role; int phonenumber; double salary; public Employee() { public static void main(String args[]) { Employee emp = new Employee("John Woo", "Java Programmer", 2125556347, 20000.00); //create an Employee object emp.printEmpInfo(); //print the Employee data } /*this method prints out all the employee's *details to the console */ } } It still has not created my Employee.class file?? and the new errors are as follows: C:\JavaPrograms\Employee.java:13: illegal start of expression public static void main(String args[]) { ^ C:\JavaPrograms\Employee.java:13: illegal start of expression public static void main(String args[]) { ^ C:\JavaPrograms\Employee.java:13: