JochemQuery
JochemQuery

Reputation: 1547

Java Could not find Main class

I have a short question i have wrote this in java. Old code:

   class apples{
        public static void main(String args[]){
            System.out.println("hello Youtube");
        }
    }

New code

public class apples{
        public static void main(String args[]){
            System.out.println("hello Youtube");
        }
    }

Eclipse give me this error:

Error: Could not find or load main class apples

What am I doing wrong? I am watching this tutorial from bucky : Youtube

Second Question:

In the tutorial there is something like Auto complete. How can I turn this on in eclipse?

FIXED: openend a file instead of class thanks for al the help!

Upvotes: 1

Views: 2802

Answers (4)

zhajiangmian
zhajiangmian

Reputation: 11

The method must be declared public and static, it must not return any value, and it must accept a String array as a parameter. The method declaration has the following form:

public static void main(String[] args)
{
    //Your code here
    System.exit(0); //Ending the program and return the given code (0 here)
}

sorry for the second question.

Upvotes: 0

Pavel K.
Pavel K.

Reputation: 436

It's preferably to use packages and declare the main method as public, but not necessary. You've made a mistake in the line 3 -- it should end with semi :

System.out.println("hello Youtube");

For Q2, the autocompletion cases appears with control-space hotkey (by default) while you're typing the code.

UPD: sorry, you MUST declare the main method public, but it's not necessary to make a class public

Upvotes: 0

JBE
JBE

Reputation: 12597

For the second question :

By Autocomplete, you probably mean "Content Assist"

You can configure it through :

Preferences>Java>Editor>Content Assist

Upvotes: 0

adarshr
adarshr

Reputation: 62573

You must have a public class for the main method to be recognizable by the JVM.

Also, try to make use of package declarations. You can have something simple such as package com.foo.examples;.

For your second question: Autocomplete is turned on by default in Eclipse. In fact, I don't know how to turn it off!

Just use the shortcut Ctrl + Space in various places and see what happens. You can also type in a class say, System followed by a dot and see all the autocompletion entries for the visible static methods of System class.

Upvotes: 7

Related Questions