Results 1 to 10 of 10
  1. #1
    NorrinGalan is offline Member
    Join Date
    Feb 2014
    Posts
    12
    Rep Power
    0

    Default InvocationTargetException

    I am developing an applet with Eclipse. I wrote code, it compiled, and ran without problem on Eclipse. However, after I have sent it to the web server, and opened the html file with my browser, I received the following error:

    Java Code:
    java.lang.reflect.InvocationTargetException
    I am thinking that there must be something wrong with my code, but I do not know how to fix it. The purpose of the program is to create a menu from which to select items, add them to a shopping cart, and finalize the bill.

    I am thinking that there must be an error with my list boxes and combo boxes event handlers.
    Last edited by NorrinGalan; 05-08-2014 at 03:55 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: InvocationTargetException

    I am uncertain that I could help you even if you provided the appropriate information (e.g. Code, Exception traces). But I am fairly certain that without that information no one on this forum will be able to assist.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    NorrinGalan is offline Member
    Join Date
    Feb 2014
    Posts
    12
    Rep Power
    0

    Default Re: InvocationTargetException

    Alright. I was not sure, if it was necessary or not. In any case, I am posting the relevant codes, mostly related to the list boxes and the combo boxes.

    Java 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]));
    			}
    		}  
    	  });
    	  
    	
      }
    }
    Last edited by NorrinGalan; 05-08-2014 at 05:27 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: InvocationTargetException

    What's the full exception, including stack trace?

    I don't see any reflection in there, so it'll be thrown from somewhere else (though I could be being blind).

    Could you also show the html applet code used to launch this applet?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,422
    Rep Power
    25

    Default Re: InvocationTargetException

    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    NorrinGalan is offline Member
    Join Date
    Feb 2014
    Posts
    12
    Rep Power
    0

    Default Re: InvocationTargetException

    I figured it out. The exception came from the code for the image definitions. I was using the wrong method.

    However, I am having issues with formatting. I want to be able to display the results with the $ sign. I have used String.format() and the NumberFormat() methods, but none works. I manage to display each subtotal, delivery, tax and result with the desired $ format. However, whenever I try to manipulate them by removing either label value I get errors.

    Here is one of the errors I get:

    Java Code:
    [CODE][CODE]Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: empty String
    	at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    	at java.lang.Double.parseDouble(Unknown Source)
    	at LanceSubs$3.actionPerformed(LanceSubs.java:391)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: empty String
    	at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    	at java.lang.Double.parseDouble(Unknown Source)
    	at LanceSubs$3.actionPerformed(LanceSubs.java:391)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    [/CODE][/CODE]


    I have thought about removing the "Remove" and "Clear" buttons from the GUI Applet.
    Last edited by NorrinGalan; 05-10-2014 at 01:25 AM.

  7. #7
    NorrinGalan is offline Member
    Join Date
    Feb 2014
    Posts
    12
    Rep Power
    0

    Default Re: InvocationTargetException

    This is only part of the code. This code, gives me errors:

    Java Code:
    	  jbtFinalize.addActionListener(new ActionListener() {
    		  @Override
    		  public void actionPerformed(ActionEvent e){
    			  double subtotal = Double.parseDouble(jlblSubtotal2.getText());
    			  double deliveryCharge = Double.parseDouble(jlblDelivery2
    				  .getText());
    			  
    			  /***final double TAX = 0.01 * Double.parseDouble(jlblTax2
    				  .getText());*/
    			  taxAmount = 0.01 * TAX_RATE * subtotal;
    			  double finalPrice = subtotal + deliveryCharge + 
    				  taxAmount;
    			  jlblTax2.setText(String.format("%4.2f", taxAmount));
    			  jtfResult.setText(String.format("$%4.2f", finalPrice));
    		  }
    	  });
    
    
    	  
    	  //Display item price and subtotal
    	  jbtRemove.addActionListener(new ActionListener() {
    		  @Override
    		  public void actionPerformed(ActionEvent e){
    			  itemPrice = Double.parseDouble(jlblItemPrice2.getText());
    			  itemSubtotal = Double.parseDouble(jlblSubtotal2.getText());
    			  itemSubtotal -= itemPrice;  
    			  taxAmount = (0.01 * TAX_RATE * itemSubtotal);
    			  
    			  if (itemPrice < 0.00)  
    				  itemPrice = 0.00;
    			  if (itemSubtotal < 0.00)
    				  itemSubtotal = 0.00;
    			  if (taxAmount < 0.00)
    				  taxAmount = 0.00;
    			  
    			  jlblItemPrice2.setText(String.format("$%4.2f", itemPrice));  
    			  jlblSubtotal2.setText(String.format("$%4.2f", itemSubtotal));  
    			  jlblTax2.setText(String.format("$%4.2f", taxAmount));  
    		  }
    	  });
    Last edited by NorrinGalan; 05-10-2014 at 01:23 AM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,422
    Rep Power
    25

    Default Re: InvocationTargetException

    The exception came from the code for the image definitions.
    So the error was in lines 44-46?
    Java Code:
      //Skipped Code
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,422
    Rep Power
    25

    Default Re: InvocationTargetException

    Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(Unkn own Source)
    at java.lang.Double.parseDouble(Unknown Source)
    at LanceSubs$3.actionPerformed(LanceSubs.java:391)
    The reasson for the error was that The code on line 391 calls the parseDouble() method with an empty String.
    Add tests in the code so it does not pass an empty String to the method.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    NorrinGalan is offline Member
    Join Date
    Feb 2014
    Posts
    12
    Rep Power
    0

    Default Re: InvocationTargetException

    I managed to fix it. Thank you for your help.

Similar Threads

  1. InvocationTargetException
    By suri_4237 in forum New To Java
    Replies: 1
    Last Post: 02-17-2014, 01:56 PM
  2. java.lang.reflect.InvocationTargetException
    By Dissonance in forum Java Applets
    Replies: 30
    Last Post: 06-10-2012, 01:22 AM
  3. InvocationTargetException on Mac
    By xEnOn in forum New To Java
    Replies: 0
    Last Post: 05-13-2011, 10:22 PM
  4. Replies: 13
    Last Post: 07-09-2010, 05:50 AM
  5. Replies: 0
    Last Post: 01-06-2010, 01:19 PM

Posting Permissions

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