1

So i'm awfully new to coding but i quite like it, i'm really young so i have 0 experience on related stuff. I'm watching this youtube series about java code and in this episode: he creates another class and uses it in the main one but im on intelij(not eclipse as he is) and it gave me two errors saying java couldnt find the symbol (my second class); my code:

package com.company;
public class Main {

    public static void main(String[] args) {

        tuna tunaObject = new tuna();
        tunaObject.simpleMessage(null);
    }

Second class:

 public class tuna{
        public void simpleMessage(){
            System.out.println("Another class");
        }
    }
1
  • 2
    By convention, class names should start with capitals. Commented Dec 28, 2015 at 0:45

2 Answers 2

4

Your simple message method does not accept parameters, so don't try to pass in any. Instead of calling simpleMessage(null) simply call simpleMessage().

Also either make sure that the tuna class is located in the same package as your main class, or import the tuna class via an import statement above the Main class and below the package declaration. Even if the two source files are in the same physical directory, the Java compiler won't understand which class you are referring to unless you specifically define each class in the same package.

Adjust your second class to:

package com.company;
public class tuna{
      public void simpleMessage(){
          System.out.println("Another class");
      }
}
Sign up to request clarification or add additional context in comments.

5 Comments

I tried that already and doesnt appear to make any diference.Its just not finding the clas no idea why
Are both classes defined in the same package?
Thanks so much, migrated the tuna class to the main class and it worked. You were right, besides being in the same directory it didnt recognized it.
You're very welcome! As you endeavor further into the world of programming, understand that every little thing you do must be very specific!
Understood that now!Thank you!
0

Wecome to Java.

Maybe you can confirm first that the second class is located in the same package with the Main. And it is better to claim a class in First letter upper-cased format.

1 Comment

Thanks.It was in the second directory but wasnt on the main class!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.