Results 1 to 19 of 19
  1. #1
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default Can't seem to get my applet to work

    Here is the URL of my applet

    h t t p : / / h r a . n e t a i . n e t / h r a / I n d e x . h t m l


    Here is my code

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package hra;
    
    import javax.swing.JApplet;
    
    /**
     *
     * @author Administrator
     */
    public class Start extends JApplet {
    
    
    
    
        /**
         * Initialization method that will be called after the applet is loaded
         * into the browser.
         */
        @Override
        public void init() {
            initComponents();
        }
    
        // TODO overwrite start(), stop() and destroy() methods
    
    
    
    
    
        /** Creates new form HRAgui */
        
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jLabel1 = new javax.swing.JLabel();
            englishButton = new javax.swing.JButton();
            somaliButton = new javax.swing.JButton();
            vietnameseButton = new javax.swing.JButton();
            cambodianButton = new javax.swing.JButton();
            hebrewButton = new javax.swing.JButton();
            chineseButton = new javax.swing.JButton();
            japaneseButton = new javax.swing.JButton();
    
           // setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
            //setTitle("Choose a Language");
    
            jLabel1.setText("Please Choose a Language");
    
            englishButton.setText("English");
            englishButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    englishButtonActionPerformed(evt);
                }
            });
    
            somaliButton.setLabel("Somali");
            somaliButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    somaliButtonActionPerformed(evt);
                }
            });
    
            vietnameseButton.setLabel("Vietnamese");
            vietnameseButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    vietnameseButtonActionPerformed(evt);
                }
            });
    
            cambodianButton.setLabel("Cambodian");
            cambodianButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cambodianButtonActionPerformed(evt);
                }
            });
    
            hebrewButton.setLabel("Hebrew");
            hebrewButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    hebrewButtonActionPerformed(evt);
                }
            });
    
            chineseButton.setLabel("Chinese");
            chineseButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    chineseButtonActionPerformed(evt);
                }
            });
    
            japaneseButton.setLabel("Japanese");
            japaneseButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    japaneseButtonActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(englishButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(somaliButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(vietnameseButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cambodianButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(hebrewButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(chineseButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(japaneseButton))
                        .addComponent(jLabel1))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(englishButton)
                        .addComponent(somaliButton)
                        .addComponent(vietnameseButton)
                        .addComponent(cambodianButton)
                        .addComponent(hebrewButton)
                        .addComponent(chineseButton)
                        .addComponent(japaneseButton))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
        }// </editor-fold>
    
        private void englishButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked English", "English", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void somaliButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Somali", "Somali", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void vietnameseButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Vietnamese", "Vietnamese", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void cambodianButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Cambodian", "Cambodian", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void hebrewButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Hebrew", "Hebrew", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void chineseButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Chinese", "Chinese", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        private void japaneseButtonActionPerformed(java.awt.event.ActionEvent evt) {
            //JOptionPane.showMessageDialog(this, "You clicked Japanese", "Japanese", JOptionPane.INFORMATION_MESSAGE);
            EnterSocial social = new EnterSocial();
            social.setVisible(true);
        }
    
        /**
        * @param args the command line arguments
        */
        
        // Variables declaration - do not modify
        private javax.swing.JButton cambodianButton;
        private javax.swing.JButton chineseButton;
        private javax.swing.JButton englishButton;
        private javax.swing.JButton hebrewButton;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JButton japaneseButton;
        private javax.swing.JButton somaliButton;
        private javax.swing.JButton vietnameseButton;
        // End of variables declaration
    }

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

  3. #3
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    And this is the error that i get when I try to load it

    load: class hra\Start.class not found.
    java.lang.ClassNotFoundException: hra.Start.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown 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)
    Caused by: java.net.SocketException: socket closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read1(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at sun.net.w w w . h t t p . C h u n k e d I n p u t S t r e a m . r e a d A h e a d B l o c k i n g (Unknown Source)
    at sun.net.w w w . h t t p . C h u n k e d I n p u t S t r e a m . r e a d A h e a d (Unknown Source)
    at sun.net. w w w . h t t p . C h u n k e d I n p u t S t r e a m . r e a d (Unknown)
    at sun.net.[ w w w . M e t e r e d S t r e a m . r e a d (Unknown Source)
    at java.io.BufferedInputStream.read1(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
    Exception: java.lang.ClassNotFoundException: hra.Start.class


    Sorry about the spaces. I don't have enough posts to post links

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

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

    Default

    My antivirus flagged your site as unsafe, by the way.

  6. #6
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    It's not a jar file. It's a .class file. I have everything in the subdirectory hra. Do you think I need to put my .class file in the hra subdirectory and then my html file at the same level as the hra dir?

  7. #7
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    really? it's probably because it's a free webhost and free domain name.

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

    Default

    Quote Originally Posted by toymachiner62 View Post
    It's not a jar file. It's a .class file. I have everything in the subdirectory hra. Do you think I need to put my .class file in the hra subdirectory and then my html file at the same level as the hra dir?
    Why not try it and find out? Let us know what happens.

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

    Default

    So I guess we'll never know if it worked or not :(

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

  11. #11
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    That didn't work. When run it as an applet through net beans it works fine. I tried running it by clicking on my html page on my pc with my Start.class file in the same folder.

    I still get this error

    java.lang.NoClassDefFoundError: Start (wrong name: hra/Start)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown 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.NoClassDefFoundError: Start (wrong name: hra/Start)


    I changed the classpath in my html file to not have the hra in front of it. I have no idea why this doesn't work.

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

    Default

    can you post your jar file here. change it to a zip file.
    Sorry i was thinking class files earlier. the Jar file should not be in another subdirectory, but the internal structure of the Jar file will reflect its package structure.

  13. #13
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    I guess I put my jar file from when my program was a JFrame online. When you create an applet it doesn't create a jar file though does it?

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

    Default

    You have to create the Jar file yourself via Java's utility. Myself, I use my IDE (Eclipse) create the Jar file. I'm sure that NetBeans has a decent Jar creation wizard. Then you set the applet code base location in the HTML file (but I'm no expert in this as I really don't do applets).

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Put your class in a folder called hra.

  16. #16
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    I've tried that. I even changed the url in my .html file on my pc so it just says "Start.class" and then I had the Start.class in the same folder as Start.html and it still gives me the same error.

  17. #17
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    That's because the class has a package declaration called hra. The directory structure must match the package declaration. Make sure the classes are in directories that match their package declarations and then create a jar file and package using instructions from the tutorial.

  18. #18
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    I got it. I created a new project and copied the code from Start.java and I was still getting the same error even though it wasn't in the package hra now. Apparently it was building the wrong project. Thanks for your help guys.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-06-2009, 12:11 AM
  2. Applet programs do not work in my JCreator
    By java_fun2007 in forum New To Java
    Replies: 7
    Last Post: 04-18-2009, 11:41 AM
  3. What are applet and how its work in java?
    By pawankumarom in forum New To Java
    Replies: 7
    Last Post: 09-05-2008, 05:26 PM
  4. Will this applet ever work?
    By willemjav in forum Java Applets
    Replies: 4
    Last Post: 04-20-2008, 05:40 PM
  5. why doesn't this short applet work?
    By kim85 in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 08:43 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
  •