Hi everyone!
I need some help in my programme. I have an error message: "error: int cannot be dereferenced" at line 134. Could you help me solve this problem, as I do not know what it means? Many thanks.

/**
 * @(#)PrizeCollection.java
 *
 * PrizeCollection application
 *
 * @author 
 * @version 1.00 2011/8/25
 */
 
import javax.swing.JOptionPane;
import java.lang.*;
import java.util.*;

public class PrizeCollection {     
		              
public static void main (String[]args) {
	
		// Declare variables and arrays which will be used in the programme
		String[] Description = new String [3];
        String[] Color = new String [3];
        int[] Value = new int [3];
 		
 		//Call the Menu
       optionMenu(Description,Color,Value);  
       	   
        }
        
        
		//Method for the menu that will appear each time a task is completed
public static void optionMenu(String Description[], String Color[], int Value[]) {
	
	int option = 0;
	while (option!=1 || option!=2 || option!=3 || option!=4){
		
    option = Integer.parseInt(JOptionPane.showInputDialog("Please choose an option: \n"
                + "1 - Enter the details of a prize \n"
                + "2 - Print the details stored for all prizes \n"
                + "3 - Search for a prize with a particular value or by description \n"
                + "4 - Quit"));
		
		if (option==1) 
		enterDetails(Description,Color,Value);
	
   		if (option==2) 
    	printDetails(Description,Color,Value);
    	if (option==3) 
    	searchDetails(Description,Color,Value);
    	if (option==4)
    	System.exit(0);}	
    	
System.exit(0);


} 


		//Method to enter details for each prize
public static void enterDetails(String Description[], String Color[], int Value[]){
for (int i=0; i<3; i++){
       Description [i] = JOptionPane.showInputDialog (null, "Please enter the description of the prize: ");
       Color [i] = JOptionPane.showInputDialog (null, "Please enter the color of the prize: ");
       Value[i] = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the value of the prize: "));
       
      
              
}
 optionMenu(Description,Color,Value);
}

		// Method to search prizes
 public static void searchDetails(String Description[], String Color[], int Value[]) {
 	
 	// A Menu if needed to choose between search by description or by value
 	 	
	int choice = 0;
	while (choice!=1 || choice!=2 || choice!=3){
		choice = Integer.parseInt(JOptionPane.showInputDialog("Please choose an option: \n"
                + "1 - Search prize by description \n"
                + "2 - Search prize by value \n"
                + "3 - Return to the previous menu"));
		
		if (choice==1) 
		searchDescription(Description,Color,Value);
		if (choice==2) 
    	searchValue(Description,Color,Value);
    	if (choice==3) 
    	optionMenu(Description,Color,Value);}
    	
    	System.exit(0);	
 	
 } 	
 	
		//Method to search by description
 public static void searchDescription(String Description[], String Color[], int Value[]){
 	
 	
 	String search_a_description = JOptionPane.showInputDialog("Please enter the name of the prize you want to search for");

 	boolean if_a_description_is_found = false; // the boolean is initialize from false
		
		//loop start here
 for (int a=0; a<Description.length; a++) // counter start from 0, the length does match a vehicle in the list and is less than i, then boolean is true and program continues

 {
 if (Description[a].equals (search_a_description)) // .equals compare 2 objects if prize type entered by user is matching of one the prize in the list then the boolean is true and program should continue
 {
 System.out.println("Successful search! A prize is found");
 System.out.println("The prize is: " + Description[a] + "\t\t Color: " + Color[a] + "\t\t Value: " + Value[a]);

 if_a_description_is_found = true; // then is this case the program will go to the next step
 }
 } // loop end here
  if (if_a_description_is_found == false)// boolean are true or false, in this case if the program cannot find the prize in the list then it should do the following
  System.out.println("No prize has been found!");
  
  optionMenu(Description,Color,Value);

  }
  
  
  		//Method to search by value
 public static void searchValue(String Description[], String Color[], int Value[]){
 
 	
 	
 	String search_a_value = JOptionPane.showInputDialog("Please enter the name of the prize you want to search for");

 	boolean if_a_value_is_found = false; // the boolean is initialize from false
		
		//loop start here
 for (int b=0; b<Value.length; b++) // counter start from 0, the length does match a prize in the list and is less than i, then boolean is true and program continues

 {
 if (Value[b].equals (search_a_value)) // .equals compare 2 objects if prize type entered by user is matching of one the prize in the list then the boolean is true and program should continue
 {
 System.out.println("Successful search! A prize is found");
 System.out.println("The prize is: " + Description[b] + "\t\t Color: " + Color[b] + "\t\t Value: " + Value[b]);

 if_a_value_is_found = true; // then is this case the program will go to the next step
 }
 } // loop end here
  if (if_a_value_is_found == false)// boolean are true or false, in this case if the program cannot find the prize in the list then it should do the following
  System.out.println("No prize has been found!");
  
  optionMenu(Description,Color,Value);

  }

 // Method to show the list of prizes
 public static void printDetails(String Description[], String Color[], int Value[]) 
 {
 for (int i=0; i<Description.length; i++) // counter start from 0, i shouldn't be less than any prize length value, counter =+1
 //.length return the length of the string type as an integer value
 {
 System.out.println("Description: " + Description[i] + "\t\t Color: " + Color[i] + "\t\t Value: " + Value[i]);
 
  // will print the list
 } // end of loop
 optionMenu(Description,Color,Value);
 } // end of method

 //method to exit the program

 public static void Exit()
 {
 	System.exit(0);
 }
} //end the program

Recommended Answers

All 5 Replies

You declare int Value[] so value on line 134 represents an int.
ints (like booleans and floats) are "primitives", not Objects, so they do not have methods. That's why your code Value.equals... gives an error - yuo try to call the equals(..) method on a primitive that does not have any methods.

Even if that was OK it still wouldn't work because Value is an int and search_a_value is a String.
You could convert the String in search_a_value to an int value, then just use == to compare that with value.

Can you explain a bit more in details as I do not know how to convert the string into an integer and vice-versa. I am just new in Java. Many thanks.

Have a look at the Integer class in the API doc
http://download.oracle.com/javase/6/docs/api/
you will find there a method called parseInt(String s)
which takes a String and parses it and returns the value as an int (provided the String represents a valid int). That's the method you need to convert your String to an int
Read the API doc for all the details.

OK. Just for your future info, the conversion the other way looks just the same:
int intValue = Integer.parseInt(stringValue);

Please keep trying with the API doc. If you looked at the method I told you in the class I told you you would have found the answer. Being able to use the API doc is an absolutely ESSENTIAL skill for anyone who wants to program in Java. You can learn the Java language quite easily, but nobody knows all the API methods. Even the most experienced developers still refer to it all the time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.