1

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!

7
  • 2
    With the code edition you've made to the question, now it's unclear what was the problem. People will eventually read perfectly correct code and wonder... Commented Jun 29, 2012 at 12:27
  • Maybe then something is wrong with the install of my java/eclipse because if this code is correct it still keep saying : Error: Could not find or load main class apples Commented Jun 29, 2012 at 12:28
  • well, have you used any package for this class (although this should not be a problem, it's a good practice)? Commented Jun 29, 2012 at 12:31
  • what's the filename of your class file? Commented Jun 29, 2012 at 12:35
  • I just followed the tutorial on youtube. Commented Jun 29, 2012 at 12:36

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Should this work? I edited the code! @MarkoTopolnik I will soon.
@JochemTheSchoolKid Please try.
@JigarJoshi I litteraly copy pasted you code in to eclipse and it still give me the error : Error: Could not find or load main class apples document is called : apples.java
in my case the file name is Main.java and class including main method name is Main
0

For the second question :

By Autocomplete, you probably mean "Content Assist"

You can configure it through :

Preferences>Java>Editor>Content Assist

Comments

0

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.