Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Problems loading Java Applet
Old 11-12-2008, 09:24 AM Problems loading Java Applet
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all,

I have compiled my Applet code and get no errors. When I try to run it in the browser I get grey box and in the bottom it says.

Applet Started

But does not load anythink, I have been to the java console and this is what it says:

Code:
java.lang.reflect.InvocationTargetException
	at java.awt.EventQueue.invokeAndWait(Unknown Source)
	at PcPerformance2.init(PcPerformance2.java:15)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at javax.swing.ImageIcon.<init>(Unknown Source)
	at PcPerformance2.initComponents(PcPerformance2.java:69)
	at PcPerformance2.access$000(PcPerformance2.java:9)
	at PcPerformance2$1.run(PcPerformance2.java:17)
	at java.awt.event.InvocationEvent.dispatch(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)
any help or advice be good thanks as really driving me nuts
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 11-12-2008, 11:59 AM Re: Problems loading Java Applet
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Looks like you're getting a nullpointer exception. I think the problem lies in the PcPerformance2.java class. Can you post your code?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-12-2008, 12:19 PM Re: Problems loading Java Applet
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author  Jamie66
 */
public class PcPerformance2 extends JApplet {
    
    //This run the into method what calls the initcomponents this
    //is where all the layout and button and layers are keep to be set up.
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
               public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
          ex.printStackTrace();
       }
    }
    
    //This is the initcomponents this builds the gui
    //it put the button on the screen the jpanle the lables everythink you see
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbPcAmount = new javax.swing.JLabel();
        txtAmount = new javax.swing.JTextField();
        lbPc1Year = new javax.swing.JLabel();
        lbPcDay = new javax.swing.JLabel();
        lbCopyWrite = new javax.swing.JLabel();
        btnCal = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        lbLogo = new javax.swing.JLabel();
        txtYear = new javax.swing.JLabel();
        txtDay = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(199, 198, 254));

        lbPcAmount.setText("Enter Performance Amount £");

        txtAmount.setText("0");

        lbPc1Year.setText("Total PcPerformance");

        lbPcDay.setText("Cost of PcPerformance per day");

        lbCopyWrite.setText("© Copywrite 2008");

        btnCal.setText("Calculate");
        btnCal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCalActionPerformed(evt);
            }
        });

        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });

        lbLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/PcPerformance/pc.jpg"))); 

        txtYear.setText("0");

        txtDay.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbPcAmount)
                            .addComponent(lbPc1Year)
                            .addComponent(lbPcDay))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtAmount, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                            .addComponent(txtYear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtDay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbCopyWrite)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnCal)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnReset)))))
                .addContainerGap(45, Short.MAX_VALUE))
            .addComponent(lbLogo, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(lbLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPcAmount)
                    .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPc1Year)
                    .addComponent(txtYear))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPcDay)
                    .addComponent(txtDay))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCal)
                    .addComponent(btnReset))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbCopyWrite)
                .addContainerGap())
        );

        lbPc1Year.getAccessibleContext().setAccessibleName("Total PcPerformance");

        add(jPanel1, java.awt.BorderLayout.CENTER);
    }

private void btnCalActionPerformed(java.awt.event.ActionEvent evt) {                                       
// this is the actionlisten for the calculation button 
    
  double x;
  String total;
  String newtotal;
  
  //This converts the string to a double.
      try {
      String xStr = txtAmount.getText();
      x = Double.parseDouble(xStr);
   }
      //This gives an error if the user inputs a letter 
   catch (NumberFormatException e) {
          // The string xStr is not a legal number.
      txtAmount.setText("Illegal data");
      return;
   }
      //value = getParameter("length"); // Get message param, if any. to get value
     //currentLength = value;
    // value = getParameter("length");
    //   currentLength = Integer.parseInt(value);  // Convert string to number.
  
      //This is where the calculation takes place 
      total = ( "£" + (x*12));
      txtYear.setText(total);
      newtotal =(((x*12)/365) +"p");
      txtDay.setText(newtotal);
         
}                                      

private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {                                         
// This is the second actionlisten that reset the fields once the button is clicked
    txtAmount.setText("0");
    txtYear.setText("0");
    txtDay.setText("0");
}                                        
 
    // Variables declaration - do not modify
    private javax.swing.JButton btnCal;
    private javax.swing.JButton btnReset;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbCopyWrite;
    private javax.swing.JLabel lbLogo;
    private javax.swing.JLabel lbPc1Year;
    private javax.swing.JLabel lbPcAmount;
    private javax.swing.JLabel lbPcDay;
    private javax.swing.JTextField txtAmount;
    private javax.swing.JLabel txtDay;
    private javax.swing.JLabel txtYear;
    // End of variables declaration
    
}
there we go
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 11-13-2008, 06:47 PM Re: Problems loading Java Applet
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Looks like you're getting a nullpointer exception.
Figures you would say that!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problems loading Java Applet
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14055 seconds with 12 queries