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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 4 of 4

Thread: Applet Error: InvocationTargerException

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Applet Error: InvocationTargerException

    I am creating a Java applet. I am using Eclipse as my IDE. I am to create an applet for a restaurant menu that allows the user to select items, and add them to a shopping cart. Then, the user can finalize it.

    The application compiles, and runs in Eclipse. However, after I have submitted the folders to the web server, and have tried to open the html file in my browser, I get the following error:

    java.lang.reflect.InvocationTargetException

    I am thinking that I have some issues with my event handling for my list boxes and combo boxes. If someone can help me identify my issues, I would appreciate. Here is the relevant code.

    import java.awt.*;
    import java.awt.event.*;
    import java.io.ObjectOutputStream.PutField;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
     
     
    public class Items extends JApplet {
     
               //Skipped Code
     
        //LIST BOXES variables
        //Create 3 arrays of Strings and 3 list boxes 
        private String[] sandwiches = {"Bacon and Turkey", "Cheese steak Melt", 
          "Veggie Lite", "The Works"};
        private String[] kids = {"Stay Fit", "Breakfast Sub", "Roast Beef", "Little Sub"};
        private String[] drinks = {"Fountain Sodas", "Vitamin Water", "Iced Tea", "Orange Juice"};
     
        private JList jlstsandwiches = new JList(sandwiches);
        private JList jlstkids = new JList(kids);
        private JList jlstdrinks = new JList(drinks);
     
        //Create 3 arrays of prices and 3 arrays of image icons
        private double[] sandwichPrices = {5.75, 6.25, 5.95};
        private double[] kidsPrices = {3.50, 2.99, 3.29};
        private double[] drinksPrices = {2.05, 1.25, 1.50};
     
        //COMBO BOXES variables
        //Create 3 arrays of Strings and 3 combo boxes
        private String[] feelings = {"Today I am...", "Feeling Happy", 
          "Feeling Strong", "Feeling Energetic"};
        private String[] specials = {"Special Sandwiches", "Big Lance", "Pepe"};
        private String[] specialDrinks = {"Special Drinks", "Lance's Shake", "Smooth It"};
     
        private JComboBox jcbofeelings = new JComboBox(feelings);
        private JComboBox jcbospecials = new JComboBox(specials);
        private JComboBox jcbodrinks = new JComboBox(specialDrinks);
     
        //Create 2 arrays of prices and 2 arrays of image icons
        private double[] specialSandwichPrices = {0.0, 6.75, 7.25};
        private double[] specialDrinksPrices = {0.0, 2.50, 2.99};
     
     
            //Skipped Code  
     
          // ---------------------------------------------------------------------------------------
          //REGISTER LISTENERS
          jlstsandwiches.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          jlstkids.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          jlstdrinks.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     
     
         //Skipped Code
     
     
          //WEST PANEL
          //Register listeners for list boxes' menus
          jlstsandwiches.addListSelectionListener(new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e){
                  /***int[] indices = jlstsandwiches.getSelectedIndices();
     
                  int i;
     
                  for(i = 0; i < indices.length; i++){
                      jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
                  }*/
     
                  int index = 0;
                  index = jlstsandwiches.getSelectedIndex();
     
                  if (index < sandwiches.length){
                      jtfItemPrice.setText(String.format("%4.2f", sandwichPrices[index]));
                  }
              }
          });
     
     
          jlstkids.addListSelectionListener(new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e){
                  /***int[] indices = jlstkids.getSelectedIndices();
     
                  int i;
     
                  for(i = 0; i < indices.length; i++){
                      jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
                  }*/
     
                  int index = 0;
                  index = jlstkids.getSelectedIndex();
                  if (index < kids.length){
                      jtfItemPrice.setText(String.format("%4.2f", kidsPrices[index]));
                  }
              }
          });
     
          jlstdrinks.addListSelectionListener(new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e){
                  /***int[] indices = jlstdrinks.getSelectedIndices();
     
                  int i;
     
                  for(i = 0; i < indices.length; i++){
                      jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
                  }*/
     
     
                  int index = 0;
                  index = jlstdrinks.getSelectedIndex();
                  if (index < drinks.length){
                      jtfItemPrice.setText(String.format("%4.2f", drinksPrices[index]));
                  }
              }
          });
     
     
          //NORTH PANEL
          //Register listeners for combo boxes
          jcbospecials.addItemListener(new ItemListener(){
            @Override
            public void itemStateChanged(ItemEvent e){
                int index = 0;
                index = jcbospecials.getSelectedIndex();
                  if (index < specials.length){
     
                      jtfItemPrice.setText(String.format("%4.2f", specialSandwichPrices[index]));
                  }   
            }  
          });
     
          jcbodrinks.addItemListener(new ItemListener(){
            @Override
            public void itemStateChanged(ItemEvent e){
                int index = 0;
                if (index < specialDrinks.length){
                    index = jcbodrinks.getSelectedIndex();
                    jtfItemPrice.setText(String.format("%4.2f", specialDrinksPrices[index]));
                }
            }  
          });
     
     
      }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Applet Error: InvocationTargerException

    What is the full text of the stack trace? In other words, what line throws the Exception?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applet Error: InvocationTargerException

    Also posted at: InvocationTargetException
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet Error: InvocationTargerException

    I figured it out. The error came from the method call for the images. I was using the wrong syntax. Thank you for your help.

Similar Threads

  1. Runtime error-- Applet program
    By amar5445 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 28th, 2013, 07:32 AM
  2. Replies: 4
    Last Post: August 16th, 2013, 03:25 PM
  3. error in print image onto applet
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2012, 08:17 PM
  4. Problem Applet Error
    By mohsendeveloper in forum Java SE APIs
    Replies: 24
    Last Post: January 19th, 2012, 04:00 PM
  5. Error while running Applet
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 1st, 2011, 04:02 AM