Results 1 to 6 of 6
  1. #1
    Zarquad is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Error message with Point.

    Hi, I'm new to this forum and to Java (I know Turing and Python). I've spent the last few weeks trying to learn Java from a textbook I downloaded online. I hope to be able to make a basic app for the play store by the end of the summer.


    So I was doing an exercise in the textbook where I had to trace this code. Sorry it isn't indented, I just copied it from the book.
    Java Code:
    public static void main (String[] args)
    	{
    	int x = 5;
    	Point blank = new Point (1, 2);
    	System.out.println (fred (x, blank));
    	System.out.println (x);
    	System.out.println (blank.x);
    	System.out.println (blank.y);
    	}
    
    	public static int fred (int x, Point p)
    	{
    	x = x + 7;
    	return x + p.x + p.y;
    	}
    When I put it into eclipse in order to see if I was right I got this error message:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Point cannot be resolved to a type
    Point cannot be resolved to a type


    I think it's saying that Point isn't a type, though I know that Java messages aren't always very helpful, lol. But yeah, any idea what's going on? I doubt it's a hard error to figure out, I'm just new to Java.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Error message with Point.

    Quote Originally Posted by Zarquad View Post
    When I put it into eclipse in order to see if I was right I got this error message:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Point cannot be resolved to a type
    Point cannot be resolved to a type


    I think it's saying that Point isn't a type,...
    No, it's saying that it does not know what the Point type is since you didn't import it. In short, you're missing the import statement.

    though I know that Java messages aren't always very helpful, lol.
    Actually, they are quite helpful 99% of the time, as they are in this case.
    Last edited by Fubarable; 07-14-2013 at 03:56 AM.

  3. #3
    Zarquad is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Re: Error message with Point.

    What's the name of the file that I have to import? Does Rectangle need an import statement as well? I haven't had to use import statements for anything that I've used so far.

    And I've had a lot of error messages that I couldn't link to the cause of the error at all. x] The textbook told me that that's pretty common. I can't give you any examples off the top of my head though.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Error message with Point.

    You don't import files, you import classes instead; the ClassLoader decides where to get the class from. The system class loader gets them from files or .jar files. As a service for the programmer the compiler imports all classes from the java.lang package implicitly; all other classes need to be imported explicitly by the programmer. The API documentation tells you the package a class belongs to.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Zarquad is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Re: Error message with Point.

    Quote Originally Posted by JosAH View Post
    You don't import files, you import classes instead; the ClassLoader decides where to get the class from. The system class loader gets them from files or .jar files. As a service for the programmer the compiler imports all classes from the java.lang package implicitly; all other classes need to be imported explicitly by the programmer. The API documentation tells you the package a class belongs to.

    kind regards,

    Jos
    Alright, thanks.

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Error message with Point.

    If you're using Eclipse, you can hover the pointer over the error and it'll offer you a list of suggestions for classes you could import to fix it. If it knows about any libraries that contain a class with that name, it'll also offer to add those to the project. (The "Fix project setup..." option.) I'm guessing you probably mean java.awt.Point, so you'd pick that from the list.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. help me with this error message
    By joel7 in forum New To Java
    Replies: 1
    Last Post: 11-27-2012, 08:10 AM
  2. Need help with error message!
    By cstampar in forum New To Java
    Replies: 2
    Last Post: 12-04-2011, 07:52 PM
  3. error message
    By tri.yudhanto in forum JDBC
    Replies: 0
    Last Post: 01-13-2011, 01:20 PM
  4. Null point exception Error
    By morya123 in forum New To Java
    Replies: 10
    Last Post: 11-25-2009, 11:22 AM
  5. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •