• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Cannot find symbol error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I'm getting the following error when I try to compile and run the code in CMD but the same code works fine in IntelliJ. Can anyone advise why this is happening? Thank you

C:\Program Files\Java\jdk-14.0.2\bin>java Buttons.java
Buttons.java:39: error: cannot find symbol
int a1 = Integer.parseInt(txt1.getText());
                ^
 symbol:   method parseInt(String)
 location: class Integer
Buttons.java:40: error: cannot find symbol
int a2 = Integer.parseInt(txt2.getText());
                ^
 symbol:   method parseInt(String)
 location: class Integer
2 errors
error: compilation failed



 
Saloon Keeper
Posts: 9426
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is your path to your project then you have a problem. A user should never put anything inside C:\Program Files.
C:\Program Files\Java\jdk-14.0.2\bin>java Buttons.java

On your command line, if you enter
java -version
what do you get?
 
pubalan somasundram
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:If this is your path to your project then you have a problem. A user should never put anything inside C:\Program Files.
C:\Program Files\Java\jdk-14.0.2\bin>java Buttons.java

On your command line, if you enter
java -version
what do you get?



This is what it get.

C:\Program Files\Java\jdk-14.0.2\bin>java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
 
Carey Brown
Saloon Keeper
Posts: 9426
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I needed to be more explicit. What if you enter:

cd \
java -version
 
Carey Brown
Saloon Keeper
Posts: 9426
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm closing up shop here for the night.

You need to create a new directory for your Buttons project that is not inside C:\Program Files. For example make a Java folder then
C:\Java\Buttons

And put your source code in it
C:\Java\Buttons\Buttons.java

And compile it:
cd \Java\Buttons
javac Buttons.java

 
pubalan somasundram
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I'm closing up shop here for the night.

You need to create a new directory for your Buttons project that is not inside C:\Program Files. For example make a Java folder then
C:\Java\Buttons

And put your source code in it
C:\Java\Buttons\Buttons.java

And compile it:
cd \Java\Buttons
javac Buttons.java



Hi Carey,

Appreciate the help. I reinstalled the JDK and reconfigured the System Variables. After that I have run the same cmd as per your advice and got this message. But I'm still getting the same error when I try to compile the buttons.java file

C:\>java -version
java version "17.0.4" 2022-07-19 LTS
Java(TM) SE Runtime Environment (build 17.0.4+11-LTS-179)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)
 
Marshal
Posts: 76100
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please tell us the contents of the folder you are using. Do you have an Integer class there?
 
pubalan somasundram
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Campbell Ritchie

This is the content. Yes, I don't have an integer class file inside.

15/07/2022  08:56 AM               251 App.class
15/07/2022  09:07 AM               342 App.java
19/07/2022  05:40 PM             1,179 Author.class
19/07/2022  05:19 PM             1,073 Author.java
29/07/2022  09:17 PM               429 bin.iml
12/07/2022  07:03 PM               259 Book.class
13/07/2022  02:32 PM               102 Book.java
13/07/2022  10:15 AM               506 BooleanOperators.class
13/07/2022  10:15 AM               298 BooleanOperators.java
25/07/2022  02:25 PM             1,593 Buttons.java
05/08/2022  11:23 AM             1,613 Buttons2.java
21/07/2022  09:21 AM             1,217 Cat.class
21/07/2022  09:21 AM               499 Cat.java
25/07/2022  11:08 AM             1,659 CurrencyConverter.class
25/07/2022  01:17 PM             1,109 CurrencyConverter.java
25/07/2022  10:21 AM             4,604 CurrencyConverter2.java
03/08/2022  05:12 PM               414 CurrencyConverter3.class
03/08/2022  05:12 PM               431 CurrencyConverter3.java
03/08/2022  05:12 PM               842 CurrencyConverterTester.java
03/08/2022  03:22 PM             1,209 CurrencyPair.class
03/08/2022  03:21 PM             1,170 CurrencyPair.java
03/06/2022  10:48 AM               258 DisplayHello.java
05/08/2022  04:55 PM               878 ECurrencyConverter.java
03/06/2022  10:40 AM               689 gui.class
12/07/2022  12:40 PM               428 Helloworld3.class
12/07/2022  12:40 PM               249 Helloworld3.java
27/05/2022  12:23 PM               432 HelloWorldApp.class
27/05/2022  12:22 PM               267 HelloWorldApp.java
03/06/2022  10:39 AM               400 My First GUI.java
03/08/2022  11:00 AM             1,071 Person.class
28/07/2022  11:14 AM               812 Person.java
03/06/2022  11:23 AM               477 PrintTest.class
03/06/2022  11:23 AM               435 PrintTest.java
03/06/2022  11:27 AM               607 PrintTest2.class
03/06/2022  11:27 AM               549 PrintTest2.java
05/08/2022  04:53 PM             1,378 Student.class
03/08/2022  12:18 PM             1,096 Student.java
01/08/2022  11:52 AM             1,380 Student1.class
03/08/2022  12:17 PM             1,096 Student1.java
05/08/2022  06:00 PM               291 Test.java
19/07/2022  05:20 PM             1,320 TestAuthor.class
19/07/2022  05:19 PM               794 TestAuthor.java
03/08/2022  11:00 AM             1,214 TestPerson.class
19/07/2022  07:15 PM               557 TestPerson.java
03/08/2022  12:18 PM             1,672 TestStudent.class
03/08/2022  12:18 PM               830 TestStudent.java
             46 File(s)         39,979 bytes[/list]
 
Saloon Keeper
Posts: 14093
319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us:

  • the exact command you are using to compile your class,
  • the working directory of your command line interpreter,
  • the output of "echo %CLASSPATH%",
  • the location of the directory containing your project,
  • the directory structure of your project.
  •  
    Saloon Keeper
    Posts: 25830
    184
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You ABSOLUTELY MUST NOT create, delete or alter any files or directories under C:\Program Files\Java\jdk-14.0.2. The JDK/'JVM directories have special integrity safeguards to protect them against hackers and accidents.

    Create your project in one of your own directories (something like "C:\Users\Myname\first_project"). You put C:\Program Files\Java\jdk-14.0.2\bin into your PATH to make it easier for the OS to find the Java executables (and which version of Java you're running with, since there can be more than one).

    I made a flat statement in the beginning and experienced users will know that it's not absolutely true, but for a beginning programmer, consider it to be inviolable law. I am old and evil in the ways of Java — since before the Millenium — and I don't muck around with stuff in the JDK directory subtree.
     
    pubalan somasundram
    Greenhorn
    Posts: 10
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hello All,

    I've managed to compile and run it via CMD with dir changed from program files to a different location. Thank you all

    C:\Users\p.somasundram\Desktop\Java>javac Buttons.java
    C:\Users\p.somasundram\Desktop\Java>java Buttons.java
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic