Kubik Sukenik Kubik Sukenik - 1 year ago 142
Java Question

java - MAC - Error: Could not find or load main class (name of class)

I'm trying to run a program written in Java using the command prompt on my Mac , but after compiling me pop up message: Error: Could not find or load main class TEST.

Maybe Im doing stupid mistake.

This is code of java program (I'm using NetBeans):

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
package test;

* @author Kuba
public class TEST {

* @param args the command line arguments
public static void main(String[] args) {


This is from my command line:

> Last login: Sat Jun 4 18:35:23 on ttys000
> Jakub-MacBook-Pro:~ Kuba$ ls
> Applications Library Pictures
> Desktop Movies Public
> Documents Music VirtualBox VMs
> Downloads NetBeansProjects
> Jakub-MacBook-Pro:~ Kuba$ cd NetBeansProjects/
> Jakub-MacBook-Pro:NetBeansProjects Kuba$ ls
> JavaApplication1 TEST
> Mocnina VypocetObvoduaObsahu
> Jakub-MacBook-Pro:NetBeansProjects Kuba$ cd TEST
> Jakub-MacBook-Pro:TEST Kuba$ ls
> build build.xml manifest.mf nbproject src
> Jakub-MacBook-Pro:TEST Kuba$ cd src
> Jakub-MacBook-Pro:src Kuba$ ls
> test
> Jakub-MacBook-Pro:src Kuba$ cd test
> Jakub-MacBook-Pro:test Kuba$ ls
> TEST.class TEST.java
> Jakub-MacBook-Pro:test Kuba$ javac TEST.java
> Jakub-MacBook-Pro:test Kuba$ java TEST
> Error: Could not find or load main class TEST
> Jakub-MacBook-Pro:test Kuba$

Thank you for any advice.

Answer Source

Jakub-MacBook-Pro:test Kuba$

This should do the trick.

cd ..
java test.TEST

Search for classpath. This is also a good read.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download