0

Could not find or load class

I can do it. When I enter the code: public class Animal { void bark() { System.out.println("Woof-Woof");} } class MyClass { public static void main(String[ ] args) { Animal dog = new Animal(); dog.bark(); } } Eclipse tell me: "Error: Could not find or load main class src.HelloWorld.Helloclass" Program (Eclipse) write in errors: "type of MyClass already defined" Help me, please, gyus!

7th Jan 2018, 6:43 PM
Aleksandr Belavin
Aleksandr Belavin - avatar
5 Respostas
+ 1
Thanks for everybody! I am stupid idiot. I had to create a code for MyClass in window for it class. But I did not it. When I corrected my mistake, the program started to work. (Sorry for my English, if anything - I'm russian)
7th Jan 2018, 7:17 PM
Aleksandr Belavin
Aleksandr Belavin - avatar
0
MyClass should be a public class in its own file. Because it's not public, Eclipse can't see it for execution
7th Jan 2018, 6:55 PM
Dan Walker
Dan Walker - avatar
0
Thanks for answer. But MyClass is "public class"
7th Jan 2018, 6:59 PM
Aleksandr Belavin
Aleksandr Belavin - avatar
7th Jan 2018, 7:05 PM
Harjeet Singh
Harjeet Singh - avatar
- 2
MyClass has no access modifier, therefore it is not public. I've just tried your code in eclipse and I can't even run an application, because main can't be seen I think. Where/what does HelloWorld.HelloClass look like? You might be trying to run in the wrong location. Also do you have another 'MyClass' in the same package/project? edit: correction, after playing around in run configurations I was able to get it to run, maybe check that
7th Jan 2018, 7:13 PM
Dan Walker
Dan Walker - avatar