how to fix java package problem in vs code

175 views Asked by At

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.

1

There are 1 answers

1
Caesar On

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.