# Error: cannot find symbol

**URL:** <https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937>\
**Category:** Data Structures\
**Created:** [June 8, 2022, 9:20pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937 "2022-06-08T21:20:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsontempo](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@johnsontempo](https://forum.codewithmosh.com/u/johnsontempo)\
**Post date:** [June 8, 2022, 9:20pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/1 "2022-06-08T21:20:50Z")

</div>

I just started learning, and I follow what the video said to type out all the code, but I got the error message said cannot find the symbol. Is there anyone know why the Array symbol cannot be found? I create my own package name, but I did choose the Array from the one I create.

![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/e/e0b1c152ff7825a900892f40a7d217e3916e48bb.png)

Appricate for help!  
Johnson Tsai

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [June 8, 2022, 11:57pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/2 "2022-06-08T23:57:22Z")

</div>

And you have an import statement at the top of your Main.java e.g. `import yourPackage.Array`?

---

<div class="post-metadata">

**Author:** ![johnsontempo](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@johnsontempo](https://forum.codewithmosh.com/u/johnsontempo)\
**Post date:** [June 9, 2022, 4:17am UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/3 "2022-06-09T04:17:49Z")

</div>

Yes, here is my code.

![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/1/1f3e8c17d9ad214a9c60d6829e0949475b34717c.png)

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [June 10, 2022, 12:34am UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/4 "2022-06-10T00:34:34Z")

</div>

Because these classes are in the same package, I think you might not need the import statement. If you remove it, does it make a difference?

---

<div class="post-metadata">

**Author:** ![johnsontempo](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@johnsontempo](https://forum.codewithmosh.com/u/johnsontempo)\
**Post date:** [June 10, 2022, 6:21am UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/5 "2022-06-10T06:21:37Z")

</div>

Interesting thing is I grab Mosh’s source code, and run the code, and got the same error message.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/f/fa55076f1cfb1e5b5e56ec5fc985c1a7fcaba883.png)

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [June 10, 2022, 3:18pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/6 "2022-06-10T15:18:39Z")

</div>

I think you have to compile the Array class first in order for that to work which typically looks like this (not sure if it is different on Windows):

```bash
javac *.java

# Alternatively, just the two classes you need:
# javac Array.java Main.java

```

Then you would run the compiled Main class’s bytecode:

```bash
java Main

```

I believe running the command you ran is only compiling `Main.java` (rather than including all of its dependencies):

```bash
java Main.java

```

NOTE: you can probably also do this in your IDE (looks like IntelliJ) there by right clicking on the `main` method in `Main.java` and then selecting whatever option the IDE has for running the Java code (possibly need to add an extension first).

---

<div class="post-metadata">

**Author:** ![johnsontempo](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@johnsontempo](https://forum.codewithmosh.com/u/johnsontempo)\
**Post date:** [June 16, 2022, 6:02pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/7 "2022-06-16T18:02:20Z")

</div>

Thank you for your suggestion, using the right click to run the program, then it works.  
but I still can’t use the terminal to run the program directly.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/3/340a7adedabcbfa986215afc1e31832eb64c7745.png)

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [June 16, 2022, 6:42pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937/8 "2022-06-16T18:42:30Z")

</div>

Actually, it looks like IntelliJ printed out the exact command line it executed in the terminal if you want to try copy-pasting that. If Java is in the `PATH` variable, you should not need to specify the full path to `java.exe` (`"C:\Program Files\Java\...\java.exe"`) and can just use `java.exe`. The `-javaagent:...` flag also looks optional if you want to drop that flag.
