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

7
  • 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. Commented Mar 20, 2020 at 11:42
  • try javac thegadgetshop.GadgetShop.java Commented Mar 20, 2020 at 11:48
  • @AbhinavChauhan I've also tried it by following this . But not found helpful. Commented Mar 20, 2020 at 11:52
  • @Jason will you elaborate more your comment makes more sense. Commented Mar 20, 2020 at 11:53
  • Can you post the project on GitHub? Commented Mar 20, 2020 at 12:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.