Java jApplet Error Invocation Exception

PEASANT KING

Commander
Registriert
Okt. 2008
Beiträge
2.412
Hallo Leute,

ich habe mir ein kleines Applet geschrieben allerdings weist es Fehler auf, zumindest wenn ich es im Browser starte hier mal der Code:

PHP:
import java.awt.event.ActionEvent;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GFMChatApplet.java
 *
 * Created on 07.07.2011, 09:20:41
 */
/**
 *
 * @author *****
 */
public class GFMChatApplet extends javax.swing.JApplet implements Runnable {
    
    private static final long serialVersionUID = 1L;
    public static final int PORT = 8765;
    Socket socket;
    DataInputStream in;
    PrintStream out;
    Thread thread;

    /** Initializes the applet GFMChatApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {
                    initComponents();
                }
            });
        } 
        catch (Exception ex) {
            ex.printStackTrace();
            System.err.println("createGUI didn't successfully complete");
        }
    }

    /** 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() {

        sendButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        outputField = new javax.swing.JTextArea();
        inputField = new javax.swing.JTextField();

        sendButton.setText("Senden");

        outputField.setColumns(20);
        outputField.setEditable(false);
        outputField.setRows(5);
        jScrollPane1.setViewportView(outputField);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(inputField, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sendButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sendButton)
                    .addComponent(inputField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>
    // Variables declaration - do not modify
    private javax.swing.JTextField inputField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea outputField;
    private javax.swing.JButton sendButton;
    // End of variables declaration

    @Override
    public void start() {
        try {
            socket = new Socket(this.getCodeBase().getHost(), PORT);
            in = new DataInputStream(socket.getInputStream());
            out = new PrintStream(socket.getOutputStream());
        } 
        catch (IOException e) {
            this.showStatus(e.toString());
            say("Verbindung zum Server fehlgeschlagen!");
        }
        say("Verbindung zum Server aufgenommen..."); //Bemerkung java-forum.org: Sollte besser am Ende des try-Blockes stehen

        if (thread == null) {
            thread = new Thread(this);
            thread.setPriority(Thread.MIN_PRIORITY);
            thread.start();
        }
    }
    
    @Override
    public void run() {
        
        String line;

            try
            {
                while(true) {
                    line = in.readLine();
                    if(line!=null) {
                        outputField.append(line+'\n' );
                    }
                }
            } 
            catch (IOException e) { 
                say("Verbindung zum Server abgebrochen"); 
            }
    }
    
    public boolean actionPerformed(ActionEvent e) {
        
        if (e.getSource() == inputField) {
            String inp= e.paramString();
            out.println(inp);
            inputField.setText("");
            return true;
        }
        return false;
    }
    
    
    public void say(String msg) {
        outputField.append("*** "+msg+" ***\n");
    }
}

Beim Aufruf im Browser bekomme ich die Meldung:
Code:
java.lang.reflect.InvocationTargetException
    at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: 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 java.lang.SecurityManager.checkExit(Unknown Source)
    at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
    at GFMChatView.initComponents(GFMChatView.java:38)
    at GFMChatView.<init>(GFMChatView.java:20)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$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)
Ausnahme: java.lang.reflect.InvocationTargetException

Allerdings verstehe ich nicht so ganz weshalb...

Grüße DJ
 
HI,

hast du dein Applet signiert? Denn für mich sieht das nach einem Berechtigungsfehler aus.

java.lang.reflect.InvocationTargetException : sagt nur aus, dass die aufgerufene Methode eine
Exception geworfen hat. Diese wird gekapselt und weitergeleitet..

Deine eigentliche Exception ist das hier:

Code:
Caused by: java.security.AccessControlException: access denied

Guck dir doch mal das hier an:

Applets signieren

Gruß crykiller
 
Wunderbar hab es segniert und es funktioniert, danke für den Hinweis.
 
Zurück
Oben