-2

enter image description here# please help me to fix such thing.

when I make a directory and inside such try to write java code this problem occurs. some time it does not give any error but when I run this code, this thing come to me Error: Could not find or load main class Test.also when i remove 'package myPkg' from my code it's works. why? is my code is wrong or any problem with vs code editor.

Reporter
  • 3,897
  • 5
  • 33
  • 47
  • Hi there, please share the error message in the plain text format – Farkhod Abdukodirov Jun 26 '23 at 01:06
  • 1
    This is fine on my machine, please show more information, such as your personal settings and the way you execute code, etc. Please see [how to ask](https://stackoverflow.com/help/how-to-ask). [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – JialeDu Jun 26 '23 at 07:47
  • May I know what's going on with the problem? If it has been solved, can you change the status of the answer to help more people with similar problems. – JialeDu Jul 07 '23 at 01:37

1 Answers1

0

I would be much easier to help if you provided the code.

What it comes to mind with this information is that you probably were writing a class without the main method, so when you didn't especified the package it used the default one wich has a main method, but when you compile in a package without a script with the main method you get that error.

When you compile a program in a IDE it always search the main method, doesn't matter whether it is in the script you are editing or no. Si always have in mind that the core of a basic java program will have a main method that initialize all the stuff.

Caesar
  • 1
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 26 '23 at 10:32