Error: Unable to find or load the main class

Solved
Dorice -  
 Dorice -
Hello to those who will see my message, I'm just starting out with Java so my problem might seem trivial to many of you but I honestly don’t know what to do '~' Before I delve a bit further into the courses available to me, I wanted to create the famous Hello World! which is probably the very first piece of code you learn to write in any programming language and I already have a problem ^^' Here's my code so there will be no ambiguity about what I typed x')

public static class Toto{ public static void main(String[] args){ System.out.println("Hello World!"); } }


So here's the very simple code I typed and I hope I didn't make any mistakes ^^'

In the terminal, I typed the following commands:

$ javac Toto.java


Nothing happened so all is well, but when I typed the next command...

$ java Toto.class


This is what the terminal responded to me
 Error: Could not find or load main class Toto.class


Yet, the file is indeed present in the folder, where I have stayed throughout my manipulations o.o

I hope someone can help me find a solution to this minor problem which is nevertheless significantly hindering my ability to progress x.x

So I was wondering if I had made a mistake during the JDK installation and I type some commands to check if that was the case and I'm sharing the results

$ javac -version javac 1.8.0_45-internal $ java -version openjdk version "1.8.0_45-internal" OpenJDK Runtime Environment (build 1.8.0_45-internal-b14) OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)


If it matters at all, I am on version 15.04 of Ubuntu and my computer is on 64 bits 'x'

Configuration: Linux / Firefox 41.0

1 réponse

KX Posted messages 19031 Status Modérateur 3 020
 
Hello,

Unlike the command
javac
which expects the path to the .java files to compile as a parameter, the command
java
takes the name of the class (not the .class file) as a parameter.

So
java Toto
would be better since the class is called Toto.
--
Trust does not exclude control.
0
Dorice
 
Thank you so much for this quick response ^^
I must admit that I feel a bit stupid right now x')
Thanks again ^o^
0