Results 1 to 4 of 4
  1. #1
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default . class not found when trying to run applet?

    So when i try to run this applet from the html file or in jcreator or textpad i get an error, here is the code:

    Java Code:
    import java.awt.*;  
    import java.awt.event.*;  
    import javax.swing.*;  
      
    public class JBankUI extends JApplet {  
      
       // array with label text for GUI  
       protected final static String names[] = { "Account number",  
          "First name", "Last name", "Balance", "Transaction Amount" };  
      
       // GUI components; protected for future subclass access  
       protected JLabel labels[];  
       protected JTextField fields[];  
       protected JButton saveButton, clearButton;  
       protected JPanel innerPanelCenter, innerPanelSouth;  
       protected final int SIZE = 5; // number of text fields in GUI  
      
       // Set up GUI  
       public void init()  
       {  
          labels = new JLabel[ SIZE ];  
          fields = new JTextField[ SIZE ];  
      
          // create labels  
          for ( int count = 0; count < labels.length; count++ )  
             labels[ count ] = new JLabel( names[ count ] );  
      
          // create text fields  
          for ( int count = 0; count < fields.length; count++ )  
             fields[ count ] = new JTextField();  
      
          // create panel to lay out labels and fields  
          innerPanelCenter = new JPanel( new GridLayout(SIZE, 2, 2, 2));  
          // equivalent code shown below, use either one...  
          //innerPanelCenter = new JPanel();  
          //innerPanelCenter.setLayout( new GridLayout(SIZE, 2, 2, 2) );  
      
          // attach labels and fields to innerPanelCenter  
          for ( int count = 0; count < SIZE; count++ ) {  
             innerPanelCenter.add( labels[ count ] );  
             innerPanelCenter.add( fields[ count ] );  
          }  
      
          // create GUI buttons  
          saveButton = new JButton("Save Record");  
          clearButton = new JButton("Clear Record");  
          // create panel to lay out buttons and attach buttons  
          innerPanelSouth = new JPanel(); //Default layout is Flow layout  
          //innerPanelSouth.setLayout( new BorderLayout() );  
          innerPanelSouth.add( saveButton );  
          innerPanelSouth.add( clearButton );  
      
          // attach panels to JApplet container  
          Container container = getContentPane();  
          //ey* setLayout( new BorderLayout() );  
          container.add( innerPanelCenter, BorderLayout.CENTER );  
          container.add( innerPanelSouth, BorderLayout.SOUTH );  
      
          //** Action Listeners implemented with an inner class  
          saveButton.addActionListener(new buttonHandler());  
          clearButton.addActionListener(new buttonHandler());  
      
          setSize(300, 200);  
          setVisible(true);  
          //validate(); // validate layout  
       } // end of init()  
      
      
       //*** Helper function: clear content of text fields  
       private void clearFields()  
       {  
          for ( int count = 0; count < SIZE; count++ )  
             fields[ count ].setText( "" );  
       }  
      
       //*** Helper function: get array of Strings with current text field contents  
       private String[] getFieldValues()  
       {  
          String values[] = new String[ SIZE ];  
      
          for ( int count = 0; count < SIZE; count++ )  
             values[ count ] = fields[ count ].getText();  
      
          return values;  
       }  
      
       /** Action Listeners implemented as private inner class*/  
        class buttonHandler implements ActionListener  
        {  
            public void actionPerformed(ActionEvent e) {  
                Object source = e.getSource();  
                if(source == saveButton) {  
                    JOptionPane.showMessageDialog(null, getFieldValues(), "Saving record...", JOptionPane.WARNING_MESSAGE);  
                }  
                else { // must be clearButton  
                    JOptionPane.showMessageDialog(null, getFieldValues(), "Clearing record...", JOptionPane.WARNING_MESSAGE);  
                    clearFields();  
                }  
            } // end of actionPerformed()  
        } // end of buttonHandler class  
    } // end class JBankUI  
      
      
      
    /*****This code implements annonimous inner class handlers for button events******** 
          saveButton.addActionListener( new ActionListener() { 
              public void actionPerformed(ActionEvent e) 
              { 
                  // source of event is already known, no need to test... 
                  JOptionPane.showMessageDialog(null, getFieldValues(), "SSaving record...", JOptionPane.WARNING_MESSAGE); 
              } // end actionPerformed() 
          } // end inner class 
          ); //end call to addActionListener() 
     
     
          //** saveButton Action Listeners implemented as Annonimous inner class 
          clearButton.addActionListener( new ActionListener() { 
              public void actionPerformed(ActionEvent e) 
              { 
                  // source of event is already known, no need to test... 
                  JOptionPane.showMessageDialog(null, getFieldValues(), "CClearing record...", JOptionPane.WARNING_MESSAGE); 
              } // end actionPerformed() 
          } // end inner class 
          ); //end call to addActionListener() 
    ************************************************/
    i get the following error in the html applet window:


    Java Plug-in 1.6.0_26
    Using JRE version 1.6.0_26-b03 Java HotSpot(TM) Client VM
    User home directory = C:\Users\David
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    load: class .class not found.
    java.lang.ClassNotFoundException: .class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.ClassNotFoundException: .class



    Whats wrong? its not the code cuz it compiles perfectly.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,950
    Rep Power
    19

    Default

    What's the tag on your page look like for the applet?

  3. #3
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    like in the html document?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,950
    Rep Power
    19

    Default

    Yes, because that tells the applet engine where to find the class file to execute.

Similar Threads

  1. class not found
    By meong in forum JDBC
    Replies: 7
    Last Post: 09-22-2010, 11:25 AM
  2. Class Not found
    By jitendra in forum AWT / Swing
    Replies: 5
    Last Post: 02-26-2010, 10:55 AM
  3. Main Class not found
    By Draugnar in forum New To Java
    Replies: 3
    Last Post: 01-09-2010, 03:12 AM
  4. applet not found in web app
    By skiungs in forum NetBeans
    Replies: 0
    Last Post: 08-26-2009, 04:09 AM
  5. No Class Def Found Error:
    By fithous in forum Java Applets
    Replies: 0
    Last Post: 04-02-2009, 05:30 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
  •