Import classes from another package

Hi, so I am trying to import a class from another project that I created, but I cannot get it to work. this is my code:

import program.GUI;

public class name {
//code
}

I get the following error

Opens a new class wizard to create a type.

package: program
public class GUI {
}

I created the program prog02> src> program> GUI.java

How can I solve it.

+4
source share
2 answers

I think I see a problem here ...

I don't know if your java works with cmd, but my explanation will assume you. Outside of using IDEs such as Netbeans and Eclipse, which greatly simplify the process of building Java code, it's good to know how this works.

Ok, here goes:

1) Java - (.class ), JAVAC

javac [optional flags] [path to file intended for compilation]

-, JVM .

2) Java- (JVM) -.

java [optional flags] [name of class file w/o .class extension]

, JVM main.java, , , .

, .

  • cd , (src)
  • javac -cp . program/ (, , , GUI.class )
  • javac -cp . Main
  • java -cp . Main

. IDE , .

+1

GUI- . :

package program;

public class GUI {
}

: Java Code

+1

Source: https://habr.com/ru/post/1613416/


All Articles