Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package ... does not exist error in intellij idea [duplicate]

I'm new in Java and can not get idea of using packages. Am I stupid or is this some kind of bug?

Guys, how to deal with this error?

C:\Users\batievskiy\IdeaProjects\JavaPset\src>java Test.java
Test.java:1: error: package pkgcalculate does not exist
import pkgcalculate.Calculator;
                   ^
Test.java:5: error: cannot find symbol
        Calculator obj = new Calculator();
        ^
  symbol:   class Calculator
  location: class Test
Test.java:5: error: cannot find symbol
        Calculator obj = new Calculator();
                             ^
  symbol:   class Calculator
  location: class Test
3 errors
error: compilation failed

enter image description here

this is Calculator code:

package pkgcalculate;

public class Calculator {
    public int add(int a, int b){
        return a+b;
    }
    public static void main(String[] args){
        Calculator obj = new Calculator();
        System.out.println(obj.add(10, 20));
    }
}

from what I got: that I cannot run Test.java from the terminal directly using: java Test.java But if I run Test with Shift + F10, the program is compiled. Why is that? Is it normal behaviour?

like image 770
Batiievskyi Avatar asked Jan 22 '26 17:01

Batiievskyi


1 Answers

If you compiling your code from command line you have to compile classes you depend on first.

Or compile them all together in one go.

like image 187
talex Avatar answered Jan 25 '26 05:01

talex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!