1

I am having trouble with running Java Applet on site. Applet itself runs localy ok from jar file and there are no errors or warning when compiling it. I even succeselfully signed it, but when I try to run it from website I always get java.lang.reflect.InvocationTargetExpection . Any ideas what I am doing wrong? Heres the applet source code:

    import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.*; 
public class test {

    private static void createAndShowGUI()  {

        JFrame frame1 = new JFrame("JAVA");
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton button = new JButton(" Remote Desktop <<");
        //Add action listener to button
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
             { 
                try   {
                Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\mstsc.exe"); //calls cmd.exe and prints hello world to console
                BufferedReader in = new BufferedReader( 
                new InputStreamReader(p.getInputStream())); 
                String line = null; 
                while ((line = in.readLine()) != null) { 
                System.out.println(line); 
                } 
                } catch (IOException l) { 
                l.printStackTrace(); 
                } 
             }

        });      

        frame1.getContentPane().add(button);
        frame1.pack();
        frame1.setVisible(true);
    }


    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

And here output from jave console:

java.lang.UnsupportedClassVersionError: button : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(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)
Exception: java.lang.UnsupportedClassVersionError: button : Unsupported major.minor version 51.0
4
  • 7
    You need to paste the cause of the InvocationTargetException. Can you show us the full trace? Commented Aug 26, 2012 at 1:45
  • This question is unanswerable without a stack trace for the exception. Voting to close ... Commented Aug 26, 2012 at 2:59
  • Do you think it has anything to do with the fact that an applet is trying to run on the host computer C:\\Windows\\System32\\mstsc.exe? Commented Aug 26, 2012 at 3:22
  • I added java console output. Any ideas? Commented Aug 26, 2012 at 10:13

1 Answer 1

1
  1. You've compiled your code with JVM version 7, but you're running your applet with an older version of the JVM (for instance 1.6).
  2. You've created a Java Application (with a main method), and not a Applett. To create an Applett your class needs to extend Applett or JApplet.
Sign up to request clarification or add additional context in comments.

1 Comment

Well, when I try to run it on machine with JVM 7 applet doesnt work either. I get java.lang.reflect.InvocationTargetException and when I look into console theres nothing. See here slovanet.sk/atavius/test/run.html Any ideas what I am doing wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.