0

I'm tearing my hair out trying to figure out why this third applet I've written behaves just fine in BlueJ but throws a "java.lang.reflect.InvocationTargetException" when I try to view it in a browser. I am still pretty much a newbie and can't figure out where to look to see the full error logs, either. Please help.

Code

/**
 * Array - Dictionary (English to Korean)
 * 
 * Jodi Rehlander
 * October, 2015 for CSci1130-51
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.applet.*;

public class Dictionary extends JApplet implements ActionListener
{
JLabel mainLabel, picLabel, header;
Image headerImg;
ImageIcon headerIcon, translateIcon;

JButton[ ] words =
    {
        new JButton( "Airplane" ),
        new JButton( "Car" ),
        new JButton( "Cat" ),
        new JButton( "Chair" ),
        new JButton( "Flag" ),
        new JButton( "Newspaper" ),
        new JButton( "Spoon" ),
        new JButton( "Paintbrush" ),
        new JButton( "Horse" ),
        new JButton( "Female" )

    };

ImageIcon[ ] pics =
    {
        new ImageIcon( "airplane.png" ),
        new ImageIcon( "car.png" ),
        new ImageIcon( "cat.png" ),
        new ImageIcon( "chair.png" ),
        new ImageIcon( "flag.png" ),
        new ImageIcon( "newspaper.png" ),
        new ImageIcon( "spoon.png" ),
        new ImageIcon( "paintbrush.png" ),
        new ImageIcon( "horse.png" ),
        new ImageIcon( "female.png" ),
    };



public void init( )
{
    //set default background to white
    getContentPane( ).setBackground( Color.WHITE );

    setLayout( new BorderLayout( ) );

    headerImg = getImage( getCodeBase( ), "headerImg.png" );
    headerIcon = new ImageIcon( headerImg );
    header = new JLabel ( headerIcon );
    add( header, BorderLayout.NORTH );




    translateIcon = new ImageIcon( );
    picLabel = new JLabel( );
    picLabel.setHorizontalAlignment( JLabel.CENTER );
    add( picLabel, BorderLayout.CENTER );


    JPanel pane = new JPanel( new GridLayout( 10, 0 ) );
    pane.setOpaque( true );
    for (int x=0; x < words.length; x++ )
    {
        words[x].addActionListener( this );
        pane.add( words[x] );
    }
    add( pane, BorderLayout.WEST );
}


public void actionPerformed( ActionEvent ae)
{
    Object obj = ae.getSource( );
    for( int x=0; x < words.length; x++ )
        if( obj == words[x] )
           picLabel.setIcon( pics[x] );




    repaint( );    
}
}

HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file automatically generated by BlueJ Java Development  -->
<!-- Environment.  It is regenerated automatically each time the  -->
<!-- applet is run.  Any manual changes made to file will be lost -->
<!-- when the applet is next run inside BlueJ.  Save into a       -->
<!-- directory outside of the package directory if you want to    -->
<!-- preserve this file. -->
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Dictionary Applet</title>
    </head>
    <body>
        <h1>Dictionary Applet</h1>
        <hr>
        <applet code="Dictionary.class" 
            width=600 
            height=500
            codebase="."

            alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
         >

            Your browser is ignoring the &lt;APPLET&gt; tag!      
        </applet>
        <hr>
    </body>
</html>

Error

    ui: Pushing modality for applet ID 1 with dialog sun.plugin.util.PluginSysUtil$DummyDialog[dialog0,-100,-100,132x38,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,3,25,126x10,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
basic: Dialog type is not candidate for embedding
ui: Pushing modality for applet ID 1 with dialog javax.swing.JDialog[dialog1,462,324,516x190,layout=java.awt.BorderLayout,TOOLKIT_MODAL,title=Application Error,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,3,25,510x162,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
ui: Pushing modality for applet ID 1 with dialog sun.plugin.util.PluginSysUtil$DummyDialog[dialog2,-100,-100,132x38,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,3,25,126x10,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]    
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    What's the HTML look like? – MadProgrammer Oct 08 '15 at 05:37
  • 1
    Copy all error info too pls - details like line and stacktrace should be there somewhere (been a while since i done java) – Daniel Brose Oct 08 '15 at 05:40
  • And which browsers are you using? – MadProgrammer Oct 08 '15 at 05:43
  • 1
    And you might like to have a look at [this](http://stackoverflow.com/questions/18285290/how-to-fix-workaround-java-lang-reflect-invocationtargetexception) and [this](http://stackoverflow.com/questions/23752595/why-do-i-get-java-lang-reflect-invocationtargetexception-in-browser-but-not-in-e) and [this](http://stackoverflow.com/questions/17135069/java-lang-reflect-invocationtargetexception-error-in-applet) – MadProgrammer Oct 08 '15 at 05:53
  • Edited to add errors. @DanielBrose – Jodi Rehlander Oct 08 '15 at 12:11
  • edited to add HTML. @MadProgrammer – Jodi Rehlander Oct 08 '15 at 12:12
  • Please post the full stack trace, not only the exception name. – StephaneM Oct 08 '15 at 12:16
  • Using IE10 and Firefox. – Jodi Rehlander Oct 08 '15 at 12:20
  • BTW - it is obvious from the HTML that the code is not in a signed Jar. No modern browser will launch an applet that is not (in a Jar and) digitally signed. Aside: Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). – Andrew Thompson Oct 08 '15 at 14:08

1 Answers1

0

To close the loop - we were meant to use unsigned .jars in the class. I had to move my arrays to the method and then it worked. So I didn't get to use my fancy instantiation but I understand a lot more about parameter availability. Thanks to all who responded.