Java Compile Error cannot find symbol

December 2016


Java Compile Error cannot find symbol




Issue


I ask for your help. I made a small program in java management auto parts that consists of 6 classes (single inheritance):
Piece-an abstract class (superclass);
Two-classes that are an extension of the class Piece:
  • PieceDeBase;
  • PieceComposite (abstract class);

Two-classes that are an extension of the class PieceComposite:
  • PieceCompositeEnKit;
  • PieceAssemblee;

A class-MainPiece which is an application of all these 5 classes.

The 6 classes are in the same directory Pieces.

When I compile the superclass Piece, so good, I no errors. By cons, when I compile the subclasses, I get an error like:


PieceDeBase.java: 7: can not find symbol symbol: class public class Piece Piece PieceDeBase extends PieceDeBase.java ^: 37: can not find symbol symbol: variable super location: class {return Prog.Pieces.PieceDeBase super.toString ()+"- -Basic ";}


These are the only errors I have for all my classes.

Here is my class Piece:


Code: package Prog.Pieces; import java.util .*; import java.io. *; public abstract class Piece {/ / Attributes --------------------- -------------------------------------------------- ----------- protected String name; protected String referenceDeBase / / Constructors ---------------------------- -------------------------------------------------- Piece () {name = "unknown"; referenceDeBase = "000000";} Piece (String n, String r) {name = n; referenceDeBase = r;} / / Accessors ------------ -------------------------------------------------- ------------------- getNom public String () {return name;} public void setNom (String n) {name = n;} public String getReferenceDeBase () {return referenceDeBase ;} public void setReferenceDeBase (String r) {r = referenceDeBase;} / / Other methods ------------------------------- --------------------------------------------- public String toString () {return name + "" + getReferenceDeBase ();} abstract public float price (); abstract public float dureeGarantie (); abstract public float dureeFabrication (); abstract public String prefix (); public String referenceDeBase () {return referenceDeBase;} public void display () {System.out.println ("Name:" + getNom () + "\ n" + "Reference:" + referenceDeBase () + "\ n" + "Price:" + price () + "euro (s) \ n "+" Guarantee: "+ dureeGarantie () +" month \ n "+" manufacturing time "dureeFabrication + () +" day (s) \ n ");} / / protected Part - -------------------------------------------------- ------------------------ afficheCommeComposants protected String (int offset) {String Decale = "" for (int i = 0; i <lag; i + + ) Decale + = ""; return Decale + name + "-" + referenceDeBase () + "\ n";}}


And here is my class PieceDeBase (just to name a few of you):


Prog.Pieces package; import java.util .*; import java.io. * public class extends PieceDeBase Piece {/ / Attributes ---------------------- ------------------------------------------- private float price; private float dureeGarantie ; private float dureeFabrication / / Constructors ------------------------------------------ ------------------- PieceDeBase () {price = 0; dureeGarantie = 0; dureeFabrication = 0;} PieceDeBase (String n, String r, float p, float dg, float df) {super (n, r); price = p; dureeGarantie = dg; dureeFabrication = df;} / / Accessors ----------------------- ----------------------------------------- public float getPrix () {return price; } public void setPrix (float p) {price = p;} public float getDureeGarantie () {return dureeGarantie;} public void setDureeGarantie (float dg) = dg {dureeGarantie;} public float getDureeFabrication () {return dureeFabrication;} public void setDureeFabrication (float df) {df = dureeFabrication;} / / Other methods ------------------------------------ ----------------------- public String toString () {return super.toString ()+"--base ";} public float price () { return price;} public float dureeGarantie () {return dureeGarantie;} public float dureeFabrication () {return dureeFabrication;} public String prefix () {return "00" + super.reference ();}}



Is this a mistake in my classpath or my code?
I really understand anything, I thought my code just yet.
If you could help me, I'd be very grateful.
Regards.

Solution


There was thus no error in my java code but rather commands via the terminal.
So for those who have the same compilation errors in a case of simple inheritance, you must build your super classes and subclasses at the same time and only once:

javac SuperClasse.java SousClasse1.java SousClasse2.java



In my case, it was:

javac Piece.java PieceDeBase.java PieceComposite.java PieceCompositeEnKit.java PieceAssemblee.java MainPiece.java


That, to me it really well and everything runs perfectly.

Note


Solved by mickeynad

Related :

This document entitled « Java Compile Error cannot find symbol » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.