0

So im getting the msg "Person cannot be resolved to a type" at Person p1,p2... and at P1,p2,p3 = new person...

Have been googling like crazy but im very new with programming and with Eclipse so im really lost at fixing this problem. I tried using this code with Sublime Text and i did actually get the same errors so is maybe the actual code the problem or is Eclipse bugging?

Thanks!

public class Ptest2main2{ public static void main(String[] arg) { Person p1, p2, p3; p1 = new Person ("Kalle anka", "123 ocean drive, orlando florida", 79); p2 = new Person ("Wile E Cotoye", "15 Acme Road, Hollywood California", 67); p3 = new Person ("Elmer Fudd", "Loony Toones Ave, bubank, California"); System.out.printf("\n%-18s%-40s%s\n", "namn", "adress", "alder"); System.out.printf (p1.skrivUt() + '\n'); System.out.printf (p2.skrivUt() + '\n'); System.out.printf (p3.skrivUt() + "\n\n"); } } 
11
  • 1
    Seems like you haven't imported Person class into your Ptest2main2 class. Commented Nov 25, 2014 at 19:19
  • Did you write a class called Person? And is it in the same directory as your Ptest2main2 class? It probably should be. Commented Nov 25, 2014 at 19:21
  • 1
    Also, you forgot to say how old Elmer Fudd is. Commented Nov 25, 2014 at 19:22
  • @DavidWallace according to Wikipedia, he's 74. Commented Nov 25, 2014 at 19:27
  • 1
    @chiastic-security 77 Commented Nov 25, 2014 at 19:30

1 Answer 1

2

Person is a class that you're trying to create instances of.

It isn't a standard Java class, which means you need to define it somewhere. Either you just haven't got a Person class and you need to create one, or you've got one, but you haven't imported it into this class.

Look at the symbol to the left of the error line in Eclipse. If it's a red cross, that means Eclipse can't think of any way of getting you out of this. If it's a lightbulb superimposed on a red cross, you can click it to get ideas for how to solve it. If there's a Person class somewhere that you haven't imported, then Eclipse should help you find it.

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

3 Comments

Or, more likely, it exists and was intended to be in the same package, so it wouldn't need to be explicitly imported; but OP decided to work in a new directory, without understanding the implication of doing so.
@DavidWallace possibly, yes. If the package declaration was wrong, though, then Eclipse would have mentioned it. In any case, I've added something about Eclipse's helpful lightbulbs, and either way it ought to do something useful here.
Seriously, I suspect that OP is a student, and they haven't learnt about packages yet, so they're just dumping everything in the default package. If he/she started a new directory for the Ptest2main2 class, Eclipse won't be able to tell him/her how to find the Person class. If this is the case, then the best advice is "put it in the same directory".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.