0

I have Java files structure like:

Gadget.java
GadgetShop.java
Mobile.java
MP3Player.java

GadgetShop.java file contains main method

package thegadgetshop;

import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class GadgetShop extends JFrame implements ActionListener 
{
....

I used this command to run the file:

javac GadgetShop.java

And I got these errors:

GadgetShop.java:44: error: cannot find symbol
private ArrayList listGadgets;
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:332: error: cannot find symbol
private Gadget getGadget(int displayNumber) {
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:265: error: cannot find symbol
Mobile mobile = new Mobile(model, size, dPrice, iWeight, iCredit);
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:265: error: cannot find symbol
Mobile mobile = new Mobile(model, size, dPrice, iWeight, iCredit);
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:297: error: cannot find symbol
MP3Player mp3Payer = new MP3Player(model, size, dPrice, iWeight, iMemory);
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:297: error: cannot find symbol
MP3Player mp3Payer = new MP3Player(model, size, dPrice, iWeight, iMemory);
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:333: error: cannot find symbol
Gadget gadget = null;
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:363: error: cannot find symbol
Gadget gadget = getGadget(iDisplayNumber);
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:375: error: cannot find symbol
if (gadget instanceof Mobile) {
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:376: error: cannot find symbol
Mobile mobile = (Mobile) gadget;
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:376: error: cannot find symbol
Mobile mobile = (Mobile) gadget;
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:382: error: cannot find symbol
if (gadget instanceof MP3Player) {
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:383: error: cannot find symbol
MP3Player mP3Player = (MP3Player) gadget;
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:383: error: cannot find symbol
MP3Player mP3Player = (MP3Player) gadget;
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:419: error: cannot find symbol
Gadget gadget = getGadget(iDisplayNumber);
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:423: error: cannot find symbol
if(gadget instanceof Mobile) {
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:425: error: cannot find symbol
Mobile mobile = (Mobile) gadget;
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:425: error: cannot find symbol
Mobile mobile = (Mobile) gadget;
^
symbol: class Mobile
location: class GadgetShop
GadgetShop.java:466: error: cannot find symbol
Gadget gadget = getGadget(iDisplayNumber);
^
symbol: class Gadget
location: class GadgetShop
GadgetShop.java:470: error: cannot find symbol
if(gadget instanceof MP3Player) {
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:472: error: cannot find symbol
MP3Player mP3Player = (MP3Player) gadget;
^
symbol: class MP3Player
location: class GadgetShop
GadgetShop.java:472: error: cannot find symbol
MP3Player mP3Player = (MP3Player) gadget;
^
symbol: class MP3Player
location: class GadgetShop
Note: GadgetShop.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
22 errors

I don't know why its not compiling and running from CMD while its running fine in Netbeans. I really need to run it from CMD.

I also used this command but got same error:

javac -Xlint GadgetShop.java

Edit 1

I have this files structure in Netbeans:

enter image description here

And files and classes structure in folder directory:

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Post your class(es). This looks like a simple case of a missed semi-colon or some illegal use of a modifier. You might also need to define the classpath for the application if you have dependencies for it. – Jason Mar 20 '20 at 11:42
  • try javac thegadgetshop.GadgetShop.java – Abhinav Chauhan Mar 20 '20 at 11:48
  • @AbhinavChauhan I've also tried it by following [this](https://docs.oracle.com/javase/tutorial/uiswing/start/compile.html) . But not found helpful. –  Mar 20 '20 at 11:52
  • @Jason will you elaborate more your comment makes more sense. –  Mar 20 '20 at 11:53
  • Can you post the project on GitHub? – Jason Mar 20 '20 at 12:01
  • when you compile make sure you're in the folder when the java files are placed. also as jason said these can be actual error in the source – Abhinav Chauhan Mar 20 '20 at 12:04
  • You probably need to compile Gadget.java first. You could also do something like "javac *.java" – NomadMaker Mar 20 '20 at 19:59

1 Answers1

0

As others have pointed out, you need to navigate to the folder where your project is to run it.

See this post, I think it will answer your question.

ADSquared
  • 207
  • 3
  • 12