2 Replies - 1542 Views - Last Post: 11 October 2012 - 07:39 PM Rate Topic: -----

#1 wolne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 28-June 12

Cannot find symbol error

Posted 11 October 2012 - 06:16 PM

Im trying to use the file that I read into my program "offerings.txt" to replace the yourChoicesItems Array. However Im getting an error and I cant figure out what to change. The error is in line 118.

AlaCarte.java:118: cannot find symbol
symbol : constructor JList(java.util.List<java.lang.String>)
location: class javax.swing.JList
JList yourChoices = new JList(lineList);

//A la Carte

   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import javax.swing.event.*;
   import java.io.BufferedReader;
   import java.io.FileReader;
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.List;

   public class AlaCarte extends JFrame implements ActionListener 
   {           
      static List<String>lineList = new ArrayList<String>();
   
      public static void main(String[] args)
      {
         BufferedReader br = null;
      
         try {
         
            String inputFile = "C:\\Users\\Whitney\\Desktop\\offerings.txt";
            String messageFile;
            
         
            FileReader fileReader = new FileReader(inputFile);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            br = new BufferedReader(new FileReader("C:\\Users\\Whitney\\Desktop\\message.txt"));
            String inputLine;
         
            
            while ((inputLine = bufferedReader.readLine()) != null)
            {
               lineList.add(inputLine);
            }
            
            fileReader.close();
            Collections.sort(lineList);
            System.out.println(lineList);
         
            while ((messageFile = br.readLine()) != null) 
            {
               System.out.println(messageFile);
            }
         
         
         } 
            catch (IOException e) 
            {
               e.printStackTrace();
            } 
         finally 
         {
            try 
            {
               if (br != null)
                  br.close();
            
            } 
               catch (IOException ex) 
               {
                  ex.printStackTrace();
               }
         }
       
         AlaCarte alc = new AlaCarte();
      }
   
   
      static String[] yourChoicesItems =
                           {"Blueberry Muffins   0.85",
                            "Strawberry Bagels   0.80",
                            "Lite Yogurt         0.75",
                            "Vanilla Ice Cream   2.75",
                            "Hash Browns         2.50",
                            "Toast               2.00",
                            "French Fries        1.50",
                            "Onion Soup          3.00",
                            "Coffee              0.90",
                            "Iced Tea            1.00",
                            "Hot Chocolate       1.75",
         						 "Burger					 2.00",
         						 "Salad					 1.75",
         						 "Water					 0.00",
         						 "Chocolate Ice Cream 2.75",
         						 "Roll					 0.75"};
   
      static double[] yourChoicesPrices = {0.85, 0.80, 0.75, 2.75,
                                       2.50, 2.00, 1.50, 3.00,
                                       0.90, 1.00, 1.75, 2.00, 1.75,
         										0.00, 2.75, 0.75};
      private JList yourChoices;
      private JTextArea  bill;
   
      private Container pane;
   
      public AlaCarte()
      {
      
         super("Welcome to Whitney's Kiosk");
      
         //Get the content pane and set its background color
         //and layout manager.
         pane = getContentPane();
         pane.setBackground(Color.yellow);
         pane.setLayout(new BorderLayout(5, 5));
      
          //Create a label and place it at NORTH. Also
          //set the font of this label.
         JLabel yourChoicesJLabel = new JLabel("Whitney's A LA CARTE MENU");
         pane.add(yourChoicesJLabel,BorderLayout.NORTH);
         yourChoicesJLabel.setFont(new Font("Dialog",Font.BOLD,18));
      
          //Create a list and place it at WEST. Also
          //set the font of this list.
         JList yourChoices = new JList(lineList);
         pane.add(new JScrollPane (yourChoices),BorderLayout.WEST);
         yourChoices.setFont(new Font("Courier",Font.BOLD,14));
      
          //Create a text area and place it at EAST. Also
          //set the font of this text area.
         bill = new JTextArea();
         pane.add(bill,BorderLayout.EAST);
         bill.setFont(new Font("Courier",Font.PLAIN,12));
      
          //Create a button and place it in the SOUTH region and
          //add an action listener.
         JButton button = new JButton("Selection Completed");
         pane.add(button,BorderLayout.SOUTH);
         button.addActionListener(this);
      
         setSize(500, 360);
         setVisible(true);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
   
           //Method to display the order and the total cost.
      private void displayBill()
      {
         int[] listArray = yourChoices.getSelectedIndices();
         double localTax = 0.01;
         double stateTax = 0.06;
         double tax;
         double subTotal = 0;
         double total;
      
         //Set the text area to non-edit mode and start
         //with an empty string.
         bill.setEditable(false);
         bill.setText("");
      
          //Calculate the cost of the items ordered.
         for (int index = 0; index < listArray.length; index++)
            subTotal = subTotal
                     + yourChoicesPrices[listArray[index]];
      
         tax = (localTax + stateTax) * subTotal;
         total = subTotal + tax;
      
          //Display the costs.
         bill.append("           Whitney's KIOSK A LA CARTE\n\n");
         bill.append("--------------- Welcome ----------------\n\n");
      
         for (int index = 0; index < listArray.length; index++)
         {
            bill.append(yourChoicesItems[listArray[index]] + "\n");
         }
      
         bill.append("\n");
         bill.append("SUB TOTAL\t\t$"
                 + String.format("%.2f", subTotal) + "\n");
         bill.append("TAX      \t\t$"
                 + String.format("%.2f", tax) + "\n");
         bill.append("TOTAL    \t\t$"
                 + String.format("%.2f", total) + "\n\n");
         bill.append("Thank you - Have a Nice Day\n\n");
      
          //Reset list array.
         yourChoices.clearSelection();
      
         repaint();
      }
   
      public void actionPerformed(ActionEvent event)
      {
         if(event.getActionCommand().equals("Selection Completed"))
            displayBill();
      }
   
   }




Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol error

#2 wolne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 28-June 12

Re: Cannot find symbol error

Posted 11 October 2012 - 06:27 PM

The program originally just used the yourChoicesItems array but I copied the items in the array and pasted them into a txt file and then read in the file, and sorted it. So what I need to do now is use the sorted file in the Jlist instead of the array.




View Postwolne, on 11 October 2012 - 06:16 PM, said:

Im trying to use the file that I read into my program "offerings.txt" to replace the yourChoicesItems Array. However Im getting an error and I cant figure out what to change. The error is in line 118.

AlaCarte.java:118: cannot find symbol
symbol : constructor JList(java.util.List<java.lang.String>)
location: class javax.swing.JList
JList yourChoices = new JList(lineList);

//A la Carte

   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import javax.swing.event.*;
   import java.io.BufferedReader;
   import java.io.FileReader;
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.List;

   public class AlaCarte extends JFrame implements ActionListener 
   {           
      static List<String>lineList = new ArrayList<String>();
   
      public static void main(String[] args)
      {
         BufferedReader br = null;
      
         try {
         
            String inputFile = "C:\\Users\\Whitney\\Desktop\\offerings.txt";
            String messageFile;
            
         
            FileReader fileReader = new FileReader(inputFile);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            br = new BufferedReader(new FileReader("C:\\Users\\Whitney\\Desktop\\message.txt"));
            String inputLine;
         
            
            while ((inputLine = bufferedReader.readLine()) != null)
            {
               lineList.add(inputLine);
            }
            
            fileReader.close();
            Collections.sort(lineList);
            System.out.println(lineList);
         
            while ((messageFile = br.readLine()) != null) 
            {
               System.out.println(messageFile);
            }
         
         
         } 
            catch (IOException e) 
            {
               e.printStackTrace();
            } 
         finally 
         {
            try 
            {
               if (br != null)
                  br.close();
            
            } 
               catch (IOException ex) 
               {
                  ex.printStackTrace();
               }
         }
       
         AlaCarte alc = new AlaCarte();
      }
   
   
      static String[] yourChoicesItems =
                           {"Blueberry Muffins   0.85",
                            "Strawberry Bagels   0.80",
                            "Lite Yogurt         0.75",
                            "Vanilla Ice Cream   2.75",
                            "Hash Browns         2.50",
                            "Toast               2.00",
                            "French Fries        1.50",
                            "Onion Soup          3.00",
                            "Coffee              0.90",
                            "Iced Tea            1.00",
                            "Hot Chocolate       1.75",
         						 "Burger					 2.00",
         						 "Salad					 1.75",
         						 "Water					 0.00",
         						 "Chocolate Ice Cream 2.75",
         						 "Roll					 0.75"};
   
      static double[] yourChoicesPrices = {0.85, 0.80, 0.75, 2.75,
                                       2.50, 2.00, 1.50, 3.00,
                                       0.90, 1.00, 1.75, 2.00, 1.75,
         										0.00, 2.75, 0.75};
      private JList yourChoices;
      private JTextArea  bill;
   
      private Container pane;
   
      public AlaCarte()
      {
      
         super("Welcome to Whitney's Kiosk");
      
         //Get the content pane and set its background color
         //and layout manager.
         pane = getContentPane();
         pane.setBackground(Color.yellow);
         pane.setLayout(new BorderLayout(5, 5));
      
          //Create a label and place it at NORTH. Also
          //set the font of this label.
         JLabel yourChoicesJLabel = new JLabel("Whitney's A LA CARTE MENU");
         pane.add(yourChoicesJLabel,BorderLayout.NORTH);
         yourChoicesJLabel.setFont(new Font("Dialog",Font.BOLD,18));
      
          //Create a list and place it at WEST. Also
          //set the font of this list.
         JList yourChoices = new JList(lineList);
         pane.add(new JScrollPane (yourChoices),BorderLayout.WEST);
         yourChoices.setFont(new Font("Courier",Font.BOLD,14));
      
          //Create a text area and place it at EAST. Also
          //set the font of this text area.
         bill = new JTextArea();
         pane.add(bill,BorderLayout.EAST);
         bill.setFont(new Font("Courier",Font.PLAIN,12));
      
          //Create a button and place it in the SOUTH region and
          //add an action listener.
         JButton button = new JButton("Selection Completed");
         pane.add(button,BorderLayout.SOUTH);
         button.addActionListener(this);
      
         setSize(500, 360);
         setVisible(true);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
   
           //Method to display the order and the total cost.
      private void displayBill()
      {
         int[] listArray = yourChoices.getSelectedIndices();
         double localTax = 0.01;
         double stateTax = 0.06;
         double tax;
         double subTotal = 0;
         double total;
      
         //Set the text area to non-edit mode and start
         //with an empty string.
         bill.setEditable(false);
         bill.setText("");
      
          //Calculate the cost of the items ordered.
         for (int index = 0; index < listArray.length; index++)
            subTotal = subTotal
                     + yourChoicesPrices[listArray[index]];
      
         tax = (localTax + stateTax) * subTotal;
         total = subTotal + tax;
      
          //Display the costs.
         bill.append("           Whitney's KIOSK A LA CARTE\n\n");
         bill.append("--------------- Welcome ----------------\n\n");
      
         for (int index = 0; index < listArray.length; index++)
         {
            bill.append(yourChoicesItems[listArray[index]] + "\n");
         }
      
         bill.append("\n");
         bill.append("SUB TOTAL\t\t$"
                 + String.format("%.2f", subTotal) + "\n");
         bill.append("TAX      \t\t$"
                 + String.format("%.2f", tax) + "\n");
         bill.append("TOTAL    \t\t$"
                 + String.format("%.2f", total) + "\n\n");
         bill.append("Thank you - Have a Nice Day\n\n");
      
          //Reset list array.
         yourChoices.clearSelection();
      
         repaint();
      }
   
      public void actionPerformed(ActionEvent event)
      {
         if(event.getActionCommand().equals("Selection Completed"))
            displayBill();
      }
   
   }



Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,895
  • Joined: 19-March 11

Re: Cannot find symbol error

Posted 11 October 2012 - 07:39 PM

AlaCarte.java:118: cannot find symbol
symbol : constructor JList(java.util.List<java.lang.String>)
location: class javax.swing.JList
JList yourChoices = new JList(lineList); 



What this means is pretty clear: there isn't a constructor that will take a List to create a JList. However, the List interface has a method toArray, which returns the contents of the list as an array. This should do the work.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1