简体   繁体   中英

Class not found exception for applet

I just finished making an applet in netbeans. But when I try to reach it using the jar file it gives me a Class not found exception error. Below are the details of the error:

Java Plug-in 10.45.2.18 Using JRE version 1.7.0_45-b18 Java HotSpot(TM) Client VM

User home directory = C:\\Users\\CC

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

0

Exception in thread "AWT-EventQueue-4" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkExit(Unknown Source)
    at java.lang.Runtime.exit(Unknown Source)
    at java.lang.System.exit(Unknown Source)
    at TicTacToe$ButtonListener.runAI(TicTacToe.java:155)
    at TicTacToe$ButtonListener.actionPerformed(TicTacToe.java:105)
    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)

Here is the code for the html.

<html>
    <head>
        <title>Minigames for All</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>

    <body>
        <h2 id="header">Welcome to Minigames for All.</h2>
        <hr>

        <div id="script">
        <object type="application/x-java-applet" height="300" width="550">
            <param name="code" value="slime2" />
            <param name="archive" value="applet/slime2.jar" />
            Applet failed to run.  No Java plug-in was found.
        </object>
        </div>

        <hr>
        <table>
            <tbody>
                <tr>
                    <td><a href="rps.html">Rock, Paper, Scissors</td>
                    <td><a href="random.html">Guess the Number</td>
                    <td><a href="ttt.html">Tic Tac Toe</td>
                </tr>


                <tr>
                    <td><a href="flip.html">Flip a Coin</td>
                    <td><a href="rpg.html">Slime RPG</td>
                    <td><a href="shoot.html">Space Shooter</td>
                </tr>

                <tr>
                    <td>&nbsp</td>
                    <td><a href="index.html">Home Page</td>
                    <td>&nbsp</td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

And here is the code for the applet:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.Random;
/**
 *
 * @author C.C
 */
public class slime extends javax.swing.JApplet {
    Random rng = new Random();
    int choice;
    int player = 100;
    int king = 100;
    int slime = 50;
    /**
     * Initializes the applet slime
     */
    @Override
    public void init() {
        choice = rng.nextInt(10)+1;
        if(choice >=7)
        {
            battle.append("You are the hero. You have 100 health." + "\n");
            battle.append("You encountered a King Slime!" + "\n\n");
        }
        else
        {
            battle.append("You are the hero. You have 100 health." + "\n");
            battle.append("You encountered a slime!" + "\n\n");
        }
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(slime.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the applet */
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the init() method 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        battle = new javax.swing.JTextArea();
        attack = new javax.swing.JButton();
        heal = new javax.swing.JButton();
        charge = new javax.swing.JButton();
        run = new javax.swing.JButton();

        battle.setColumns(20);
        battle.setRows(5);
        jScrollPane1.setViewportView(battle);

        attack.setText("Attack");
        attack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                attackActionPerformed(evt);
            }
        });

        heal.setText("Heal");
        heal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                healActionPerformed(evt);
            }
        });

        charge.setText("Charge");
        charge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chargeActionPerformed(evt);
            }
        });

        run.setText("Run");
        run.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                runActionPerformed(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)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(heal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(attack, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(charge, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(run, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(attack)
                    .addComponent(charge))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(heal)
                    .addComponent(run))
                .addContainerGap())
        );
    }// </editor-fold>                        

    private void attackActionPerformed(java.awt.event.ActionEvent evt) {                                       
        int damage = rng.nextInt(10)+1;
       int damage2 = rng.nextInt(25)+10;
       int damage3 = rng.nextInt(20)+5;
       if(player <= 0)
       {
           battle.append("You have died" + "\n\n");
           System.exit(0);
       }
       else
       {
            if(damage >=7)
            {
                battle.append("You did "+ String.valueOf(damage)+ " damage. It was a critcal hit!" + "\n");
                if (choice >=7)
                {
                    king = king-damage;
                    battle.append("The King Slime has " + king + " health left!" + "\n");
                    if(king <=0)
                    {
                        battle.append("You have defeated the King Slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
                    player = player-damage2;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
                else
                {
                    slime = slime-damage;
                    battle.append("The slime has " + slime + " health left!" + "\n");
                    if(slime <=0)
                    {
                        battle.append("You have defeated the slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
                    player = player-damage3;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");                  
                }
            }
            else
            {
                battle.append("You did "+ String.valueOf(damage)+ " damage." + "\n");
                if (choice >=7)
                {
                    king = king-damage;
                    battle.append("The King Slime has " + king + " health left!" + "\n");
                    if(king <=0)
                    {
                        battle.append("You have defeated the King Slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The Slime King hit you for " + String.valueOf(damage2) + " damage!" + "\n");
                    player = player-damage2;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
                else
                {
                    slime = slime-damage;
                    battle.append("The slime has " + slime + " health left!" + "\n");
                    if(slime <=0)
                    {
                        battle.append("You have defeated the slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
                    player = player-damage3;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
            }
       }
    }                                      

    private void healActionPerformed(java.awt.event.ActionEvent evt) {                                     
        int heal = rng.nextInt(40)+20;
       int damage2 = rng.nextInt(25)+10;
       int damage3 = rng.nextInt(20)+5;
       if(player <= 0)
       {
           battle.append("You have died" + "\n\n");
           System.exit(0);
       }
       else
       {
           battle.append("You healed for " + heal + " health.\n");
           player = player+heal;
           if (choice >=7)
                {               
                    battle.append("The King Slime has " + king + " health left!" + "\n");       
                    battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
                    player = player-damage2;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
                else
                {
                    battle.append("The slime has " + slime + " health left!" + "\n");
                    battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
                    player = player-damage3;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");                  
                }
       }
    }                                    

    private void chargeActionPerformed(java.awt.event.ActionEvent evt) {                                       
        int damage = rng.nextInt(30)+10;
       int damage2 = rng.nextInt(25)+10;
       int damage3 = rng.nextInt(20)+5;
       if(player <= 0)
       {
           battle.append("You have died" + "\n\n");
           System.exit(0);
       }
       else
       {
            battle.append("You skip a turn to charge a more powerful attack!" +"\n");
            if (choice >=7)
                {               
                    battle.append("The King Slime has " + king + " health left!" + "\n");       
                    battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
                    player = player-damage2;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
                else
                {
                    battle.append("The slime has " + slime + " health left!" + "\n");
                    battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
                    player = player-damage3;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");                  
                }
            if(player <=0)
            {
                battle.append("You have died" + "\n\n");
                System.exit(0);
            }
            else
            {
                if (choice >=7)
                {
                    battle.append("You unleash a powerful attack at the King Slime for " + damage + " damage.\n");
                    king = king-damage;
                    battle.append("The King Slime has " + king + " health left!" + "\n");
                    if(king <=0)
                    {
                        battle.append("You have defeated the King Slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The King Slime hit you for " + String.valueOf(damage2) + " damage!" + "\n");
                    player = player-damage2;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");
                }
                else
                {
                    battle.append("You unleash a powerful attack at the slime for " + damage + " damage.\n");
                    slime = slime-damage;
                    battle.append("The slime has " + slime + " health left!" + "\n");
                    if(slime <=0)
                    {
                        battle.append("You have defeated the slime!" + "\n\n");
                        System.exit(0);
                    }
                    battle.append("The slime hit you for " + String.valueOf(damage3) + " damage!" + "\n");
                    player = player-damage3;
                    if(player < 0)
                    {
                        player = 0;
                    }
                    battle.append("You have "+ String.valueOf(player) + " health left." + "\n\n");                  
                }
            }

       }
    }                                      

    private void runActionPerformed(java.awt.event.ActionEvent evt) {                                    
        battle.append("You can't run in this game you sissy.\n\n");
    }                                   

    // Variables declaration - do not modify                     
    private javax.swing.JButton attack;
    private javax.swing.JTextArea battle;
    private javax.swing.JButton charge;
    private javax.swing.JButton heal;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton run;
    // End of variables declaration                   
}

You received AccessControlException exception which means the operation was not allowed.

You should not call System.exit() in the applet. Applets normally not allowed to execute it. As System.exit() terminates JVM you may terminate other applets that are currently running in the browser. See What Applets Can and Cannot Do for more details.

Redesign the applet to navigate to a document that indicates that the execution of applet is over. You can use applet.getAppletContext().showDocument() for that purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM