Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default java app - volume of cylinder

    I been using java for only a few months and recently started creating applets in netbeans, when I run this applet I get an error message saying

    Start: applet not initialized.

    below in the netbeans output window is the message

    Java Code:
    run:
    java.lang.NullPointerException
            at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
            at java.lang.Double.parseDouble(Double.java:510)
            at NewJApplet.init(NewJApplet.java:28)
            at sun.applet.AppletPanel.run(AppletPanel.java:424)
            at java.lang.Thread.run(Thread.java:619)

    There are no errors messages showing up in the code window, I have set it up the same as previous applets which worked. Not sure if I am missing a line of code or formatted it wrong. Would really appreciate some help with this as I have spent a hour or two going over the code and have no idea whats wrong. Thanks



    The full code below

    Java Code:
    import java.awt.Container;
    import javax.swing.JApplet;
    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
    
    /**
     *
     * @author HAL
     */
    public class NewJApplet extends JApplet {
    
        /**
         * Initialization method that will be called after the applet is loaded
         * into the browser.
         */
        public void init() 
        {
            
           String radiusStr = null ;
           String heightStr = null;
       
            double volume = 0;
            double radius= Double.parseDouble(radiusStr);
            double height= Double.parseDouble(heightStr);
    
            JTextArea outputArea= new JTextArea();
    
            Container container =getContentPane();
    
            container.add(outputArea);
    
      
    
             for (int i = 1; i <= 5; i++ ){
    
            radiusStr = JOptionPane.showInputDialog("Enter in the radius here");
            heightStr  = JOptionPane.showInputDialog("Enter in the radius here");
    
            outputArea.setText("The Volume of the Cylinder is" +volume);
             }
    
        }
           public double myvolume (double radius, double height)
            {
    
            double volume;
    
             volume= Math.PI*radius*radius*height;
    
            return volume;
    
         } // end of method
    } // end of volume class

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I don't know about applet not initialized, but your code should cause a null pointer exception here:

    Java Code:
        String radiusStr = null;
        String heightStr = null;
    
        double volume = 0;
        double radius = Double.parseDouble(radiusStr); // ***** here *****
        double height = Double.parseDouble(heightStr); // ***** here *****
    At the indicated line, you are trying to parse a null string, and this is not allowed. You shouldn't be attempting this here but rather in an ActionListener's actionPerformed method that is called by a JButton.

    edit: scratch the bit about ActionListener as I see that you are using a bunch of JOptionPanes. Then what you must do is use the information obtained from the JOptionPanes in your calculation. Right now you're throwing this information away.
    Last edited by Fubarable; 02-27-2010 at 05:16 PM.

Similar Threads

  1. Morph Cone to Cylinder!
    By aRTx in forum Advanced Java
    Replies: 2
    Last Post: 05-09-2009, 05:50 PM
  2. High Volume of Spam Lately On the forum
    By Java Tip in forum Suggestions & Feedback
    Replies: 16
    Last Post: 04-28-2009, 07:38 AM
  3. Volume of AudioClip
    By Fedor in forum New To Java
    Replies: 0
    Last Post: 04-25-2009, 04:16 PM
  4. Manually edit volume of MIDI file in Java
    By Ravaa in forum New To Java
    Replies: 1
    Last Post: 03-04-2009, 05:57 PM
  5. Cylinder
    By Manikyr in forum New To Java
    Replies: 1
    Last Post: 02-28-2009, 03:58 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
  •