How to fix the symbol not found error in my code

Brodie picture Brodie · Sep 8, 2013 · Viewed 9.5k times · Source
// An illustration of object creation.
class ShipMain1 {
    public static void main(String[] args){
    // Define a method variable to refer to a Ship object.
    Ship argo;
    // Construct a new Ship object.
    argo = new Ship();
    }
}

When I go to compile it, it tells me symbol can not be found for the Ship in both Ship argo and argo = new Ship(); please help I'm an extremely new beginner. I'm also copying this out of a programming book so I don't know why it's not working.

Answer

C.Champagne picture C.Champagne · Sep 9, 2013

An object is an instance of a class. You need thus to have a class defined somewhere. In your case, you certainly forgot to copy the Ship class.

You can just create the missing class the same way you created ShipMain1. No need to create any method. The following should work.

public class Ship{}

A faster solution is to use the class where the main method is defined. You can rename the class ShipMain1 to Ship or set a argo as an instance of ShipMain1.