Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Semantic error: Variable assignment: please help!!

  1. #1
    Join Date
    Nov 2009
    Thanked 0 Times in 0 Posts

    Default Semantic error: Variable assignment: please help!!

    HI all I have come across an error and I dont understand why I have got it.

    I have 2 variables called box1 and box2 referencing objects. both objects have 2 attributes, these are colour and position.

    the error occurs when I execute the following statement: [I][box2 = box1.getPosition();/I]

    I get the error message: [I][Semantic error: Variable assignment: box1: Can't assign
    primitive value to object type:class Box/I]

    if anyone could explain this eror it would me a great deal and I will ofcourse thank the person who helps in the correct way.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: Semantic error: Variable assignment: please help!!

    You are attempting to assign a primitive value (int, long, float, etc...) to an object (Box?), which cannot be done (values assigned to objects using equality must be of the same object class). What is the behavior you wish to have with this code, to assign the position of box2 to that of box1? Should probably be something more along these lines:
        box2.setPosition( box1.getPosition() );

  3. The Following User Says Thank You to copeg For This Useful Post:

    humdinger (November 18th, 2009)

Similar Threads

  1. New assignments for JAVA beginners
    By Peetah05 in forum File I/O & Other I/O Streams
    Replies: 24
    Last Post: April 24th, 2009, 11:33 AM
  2. Java program for to implement supermarket menu
    By 5723 in forum AWT / Java Swing
    Replies: 1
    Last Post: April 14th, 2009, 03:14 AM
  3. How to use for loop for movement of points in a picture display?
    By Dman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2009, 09:19 AM
  4. [SOLVED] Problem with Grading calculator in java program
    By Peetah05 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: March 28th, 2009, 04:25 PM