" Error: Could not find or load main class" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

" Error: Could not find or load main class"

Hi. I was practicing making classes on a program. And when i tried to call the method, it said that the program could not find or load main class. I will post the code below. someone help me please. Thanks for your attention. /* * 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 javaapplication3; interface car { void speedup(int accelaratedspeed); void usebrake(int brakeefficiency); void changegear(int changedgear); } public class TOYOTAcar implements car { public void main(String[] args) { printstates(); } int size = 0; int speed = 0; String color = "unknown"; int gear = 1; public void setsize(int newsize) { size = newsize; } @Override public void speedup(int accelaratedspeed) { speed = speed + accelaratedspeed; } @Override public void usebrake(int brakeefficiency) { speed = speed - brakeefficiency; } @Override public void changegear(int changedgear){ gear = changedgear;} public void printstates () { System.out.println("size:"+ size +" speed:" + speed + " Gear:" + gear); }}

31st May 2017, 4:12 AM
MassiveMayhem
3 Answers
+ 7
A valid entry point in java is the main method and it should be public static void: public static void main(String args[]){ } So, I think you missed the static keyword in your main method's declaration. And I would suggest not to write the main method in class TOYOTAcar, but make a separate class with main. There are some well known good practices for designing classes.. one of them is called "Single responsibility". So TOYOTAcar shouldn't be responsible to start your program IMHO.
31st May 2017, 5:03 AM
Aibek T.
Aibek T. - avatar
+ 4
@Mr Programmer lowercase 'm'! 😝
31st May 2017, 4:55 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
you spelled it wrong. its public static void main(String[] args)
31st May 2017, 4:37 AM
MR Programmer
MR Programmer - avatar