Closed Thread
Results 1 to 2 of 2

Thread: Getting: int cannot be dereferenced

  1. #1
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Getting: int cannot be dereferenced

    Can't figure out where I am going wrong. New to java programming so please bare with me. I keep getting the "int cannot be dereferenced" error on program below. Tried changing things around, only makes it worse. I pasted the program first and error msg. below it. Any advise would be greatly appreciated.

    import java.util.Scanner;
    public class Furniture
    {
    public static void main(String[] args)
    {
    int woodType;
    String chosenCode = "";
    double chosenCost = 0;
    Furniture selectedFurniture = new Furniture();
    final int PINE_CODE = 1;
    final int OAK_CODE = 2;
    final int MAHOGANY_CODE = 3;
    final double PINE_COST = 100;
    final double OAK_COST = 225;
    final double MAHOGANY_COST = 310;
    boolean choiceIsGood = true;
    Scanner input = new Scanner(System.in);
    System.out.println("What type of wood do you want ");
    System.out.println("Enter " + PINE_CODE + " for Pine " +
    OAK_CODE + " for Oak, or " + MAHOGANY_CODE + " for Mahogany... ");
    woodType = input.nextInt();
    if(woodType == PINE_CODE)
    chosenCost = PINE_COST;
    else
    if(woodType == OAK_CODE)
    chosenCost = OAK_COST;
    else
    if(woodType == MAHOGANY_CODE)
    chosenCost = MAHOGANY_COST;
    else
    choiceIsGood = false;
    if(choiceIsGood)
    {
    woodType.setCode(chosenCode);
    woodType.setCost(chosenCost);
    }
    else
    System.out.println("You entered " + woodType + " which is invalid.");
    System.out.println("Wood choise: ");
    System.out.println("Type: " + woodType.getType() +
    " Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
    }
    }

    Error msgs.

    Furniture.java:34: int cannot be dereferenced
    woodType.setCode(chosenCode);
    ^
    Furniture.java:35: int cannot be dereferenced
    woodType.setCost(chosenCost);
    ^
    Furniture.java:40: int cannot be dereferenced
    System.out.println("Type: " + woodType.getType() +
    ^
    Furniture.java:41: int cannot be dereferenced
    " Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
    ^
    Furniture.java:41: int cannot be dereferenced
    " Table: " + woodType.getWood() + " Cost is " + woodType.getCost());
    ^
    5 errors

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Getting: int cannot be dereferenced

    You declared woodType as an int. It doesn't have a getCost(), getWood(), setCode(), setCost() or getType() method.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. int cannot be dereferenced?
    By nain33 in forum Java Help
    Replies: 2
    Last Post: 04-04-2011, 05:02 AM
  2. Help with int cannot be dereferenced error
    By Cool Runnings in forum Java Help
    Replies: 3
    Last Post: 01-29-2010, 02:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

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