0

I am a new coder, taking an introduction Java course. My operating system is Windows 10. Around 4 - 5 months ago we initially set up the class path, ran our "Hello World" program from the command line, and never used it again.

Now we are doing an exercise with input / output re-direction to files, and I must of forgotten what my class path was, so I am trying to set it up again.

I have set up my classpath using the command:

set CLASSPATH=C:\Users\grant\IdeaProjects;

I then try to run my program, which is in the directory C:\Users\grant\IdeaProjects\SessionTwo\src\AssignmentFive\HexToDec.Class by typing:

java SessionTwo.src.AssignmentFive.HexToDec

I get the following error:

Error: Could not find or load main class IdeaProjects.SessionTwo.src.AssignmentFive.HexToDec Caused by: java.lang.ClassNotFoundException: IdeaProjects.SessionTwo.src.AssignmentFive.HexToDec

I have played with this quite a bit, but keep getting the error. Looking for any help on what I am doing wrong.

Thanks!

DntMesArnd
  • 115
  • 9

1 Answers1

2

You should set CLASSPATH to the parent directory which contains your code. In this case, that appears to be C:\Users\grant\IdeaProjects\SessionTwo\src\. You then should run your program using just the package name as declared at the top of the .java file, followed by the class name: AssignmentFive.HextToDec.

Note that if you run your program inside of IntelliJ IDEA, it will take care of all these details for you.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Thanks for helping! I have tried that, and am getting the same error. Is there a potential Syntax error? I have tried finishing the set classpath f with a ; with the \ and without anything? – DntMesArnd Jul 31 '18 at 00:52
  • "Is there a potential Syntax error?" I cannot begin to guess the answer to this question. The only way to determine if your code has any syntax errors is to see your code. You can edit your question to include it. Be sure that your code is indented according to Java standards so that we can read it more easily. – Code-Apprentice Jul 31 '18 at 00:53
  • The classpath seems to be set up. When I run set CLASSPATH, it shows CLASSPATH=CLASSPATH=C:\Users\grant\IdeaProjects\SessionTwo\src; Assuming the problem is with my loading statement of java AssignmentFive.HexToDec – DntMesArnd Jul 31 '18 at 01:04
  • @DntMesArnd What is the directory and file structure in that `src` directory. Do you have `package` declarations at the top of each .java file? Please edit your question to show this information. – Code-Apprentice Jul 31 '18 at 01:07
  • Ok, I got it working now. Not sure what really changed, what I did wrong, but it is working now. Maybe my crappy typing..... I appreciate the help and time dude. – DntMesArnd Jul 31 '18 at 01:14