473,473 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help figuring out why this won run

2 New Member
Hi everyone,
I am making a quick potato head applet for my java class. I set it up but for some reason it keeps giving me a java.lang.NullPointerException
and i dont know what to do. Here is my script and if any fixes or sugestions can be offered it would be appreciated. dont mind that the images are all the same i just havent changed that
================================================== =

package potato;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class PotatoHead
extends Applet implements ActionListener, ItemListener {
boolean isStandalone = false;
Choice hair,hat,glasses,beard,outfit,accessories;
Image aHair,bHair,cHair,dHair;
Image aHat,bHat,cHat,dHat;
Image aBeard,bBeard,cBeard;
Image aOutfit,bOutfit,cOutfit;
Image aAcess,bAcess,cAcess;
Image aGlass,bGlass;
int hOption,htOption,bOption,oOption,aOption,gOption;
BorderLayout borderLayout1 = new BorderLayout();


//Construct the applet
public PotatoHead () {
}

//Initialize the applet
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

//Component initialization
private void jbInit() throws Exception {
hair = new Choice();
hair.add("None");
hair.add("Fro");
hair.add("Clown");
hair.add("PinkGirl");

hat = new Choice();
hat.add("None");
hat.add("Boulder Derbie");
hat.add("Wizzard");
hat.add("Fez");

glasses = new Choice();
glasses.add("None");
glasses.add("EyePatch");

beard = new Choice();
beard.add("None");
beard.add("Handlebar");
beard.add("FumanChu");

outfit = new Choice();

outfit.add("Biker");
outfit.add("Fancy");
outfit.add("Barney");

accessories = new Choice();
accessories.add("None");
accessories.add("scar");
accessories.add("unibrow");

hair.addItemListener(this);
add(hair);
aHair = getImage(getDocumentBase(),"Campion Start.GIF");
bHair = getImage(getDocumentBase(),"boyHair.gif");
cHair = getImage(getDocumentBase(),"boyHair.gif");
dHair = getImage(getDocumentBase(),"boyHair.gif");

hat.addItemListener(this);
add(hat);
aHat = getImage(getDocumentBase(),"WOMANHAIR.GIF");
bHat = getImage(getDocumentBase(),"boyHair.gif");
cHat = getImage(getDocumentBase(),"boyHair.gif");
dHat = getImage(getDocumentBase(),"boyHair.gif");

beard.addItemListener(this);
add(beard);
aBeard = getImage(getDocumentBase(),"WOMANHAIR.GIF");
bBeard = getImage(getDocumentBase(),"boyHair.gif");
cBeard = getImage(getDocumentBase(),"boyHair.gif");


outfit.addItemListener(this);
add(outfit);
aOutfit = getImage(getDocumentBase(),"WOMANHAIR.GIF");
bOutfit = getImage(getDocumentBase(),"boyHair.gif");
cOutfit = getImage(getDocumentBase(),"boyHair.gif");


glasses.addItemListener(this);
add(glasses);
aGlass = getImage(getDocumentBase(),"WOMANHAIR.GIF");
bGlass = getImage(getDocumentBase(),"boyHair.gif");

accessories.addItemListener(this);
add(accessories);
aAcess= getImage(getDocumentBase(),"WOMANHAIR.GIF");
bAcess = getImage(getDocumentBase(),"boyHair.gif");
cAcess = getImage(getDocumentBase(), "boyHair.gif");




}

//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
public void paint(Graphics g){
//================================================== ===
// Hair Option
//================================================== ===
if (hOption == 1){
g.drawImage(aHair, 50, 50, 100, 100, this);
}
if (hOption == 2){
g.drawImage(bHair, 50, 50, 100, 100, this);
}
if(hOption == 3){
g.drawImage(aHair, 50, 50, 100, 100, this);
}
if (hOption == 4){
g.drawImage(bHair, 50, 50, 100, 100, this);
}
//================================================== ========
// Hat Options
//================================================== ========
if (htOption == 1){
g.drawImage(aHat, 50, 50, 100, 100, this);
}
if (htOption == 2){
g.drawImage(bHat, 50, 50, 100, 100, this);
}
if(htOption == 3){
g.drawImage(cHat, 50, 50, 100, 100, this);
}
if (htOption == 4){
g.drawImage(dHat, 50, 50, 100, 100, this);
}
//================================================== ========
// Glasses Option
//================================================== ========
if (gOption == 1){
g.drawImage(aGlass, 50, 50, 100, 100, this);
}
if (gOption == 2){
g.drawImage(bGlass, 50, 50, 100, 100, this);
}
//================================================== ========
// Beard Options
//================================================== ========
if (bOption == 1){
g.drawImage(aBeard, 50, 50, 100, 100, this);
}
if (bOption == 2){
g.drawImage(bBeard, 50, 50, 100, 100, this);
}
if(bOption == 3){
g.drawImage(cBeard, 50, 50, 100, 100, this);
}
//================================================== ========
// Accessories Options
//================================================== ========
if (aOption == 1){
g.drawImage(aAcess, 50, 50, 100, 100, this);
}
if (aOption == 2){
g.drawImage(bAcess, 50, 50, 100, 100, this);
}
if(aOption == 3){
g.drawImage(cAcess, 50, 50, 100, 100, this);
}
//================================================== ========
// Outfit Options
//================================================== ========
if (oOption == 1){
g.drawImage(aOutfit, 150, 150, 100, 100, this);
}
if (oOption == 2){
g.drawImage(bOutfit, 150, 150, 100, 100, this);
}
if(oOption == 3){
g.drawImage(cOutfit, 150, 150, 100, 100, this);
}

}




//Main method
public static void main(String[] args) {
PotatoHead applet = new PotatoHead();
applet.isStandalone = true;

Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");

frame.add(applet, BorderLayout.CENTER);

applet.init();
applet.start();
frame.setSize(600, 600);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation( (d.width - frame.getSize().width) / 2,
(d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}

public void itemStateChanged(ItemEvent e) {

// Hair
if (e.getSource()== hair){
String hairChoice = e.getItem().toString();
if(hairChoice.equals("None")){
hOption=1;
}
if(hairChoice.equals("Fro")){
hOption=2;
}
if(hairChoice.equals("Clown")){
hOption=3;
}
if(hairChoice.equals("PinkGirl")){
hOption=4;
}
// Hat
if (e.getSource()== hat){
String hatChoice = e.getItem().toString();
if (hatChoice.equals("None")) {
htOption = 1;
}
if (hatChoice.equals("BoulderDerbie")) {
htOption = 2;
}
if (hatChoice.equals("Wizzard")) {
htOption = 3;
}
if (hatChoice.equals("Fez")) {
htOption = 4;
}
}
// Glasses
if (e.getSource()== glasses){
String glassesChoice = e.getItem().toString();
if(glassesChoice.equals("None")){
gOption=1;
}
if(glassesChoice.equals("EyePatch")){
htOption=2;
}
}
// Beard
if (e.getSource()== beard){
String beardChoice = e.getItem().toString();
if(beardChoice.equals("None")){
bOption=1;
}
if(beardChoice.equals("Handlebar")){
bOption=2;
}
if(beardChoice.equals("FumanChu")){
bOption=3;
}
}
// Outfit
if (e.getSource()== outfit){
String outfitChoice = e.getItem().toString();
if(outfitChoice.equals("Biker")){
oOption=1;
}
if(outfitChoice.equals("Fancy")){
oOption=2;
}
if(outfitChoice.equals("Barney")){
oOption=3;
}
}
// Acessesories
if (e.getSource()== accessories){
String accessoriesChoice = e.getItem().toString();
if(accessoriesChoice.equals("Nonw")){
aOption=1;
}
if(accessoriesChoice.equals("scar")){
aOption=2;
}
if(accessoriesChoice.equals("unibrow")){
aOption=3;
}
}







}
repaint();
}

public void actionPerformed(ActionEvent e) {
}
}
Dec 18 '07 #1
1 1301
r035198x
13,262 MVP
1.) Please use code tags when posting code
2.) I could look at your code and tell you which variable is null and being derefenced but better is that you look at your stacktrace again. It tells you the exact line number where the exception was thrown.
Dec 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Nathan Pinno | last post by:
Hi all, I need help figuring out how to fix my code. I'm using Python 2.2.3, and it keeps telling me invalid syntax in the if name == "Nathan" line. Here is the code if you need it. #This...
2
by: Roberto Leibman | last post by:
I haven't been able to figure this out, or find any resource for this. I'd like to be able to know, in javascript, if the media that's rendering is screen or print. I have no nefarious purpose...
7
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One...
1
by: Darin Browne | last post by:
We figure budgets in 26 14 days periods in a year. I currently can take a date and calculate which of those 26 periods that date falls in. Now I have to figure out what is beginning and ending...
0
by: you | last post by:
Hiya! I am having some trouble figuring out how to use reflection in a specific way and was wondering if anyone could help. I hope that I can explain what I am trying to do clearly so bear with...
13
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
2
by: kristopher.erickson | last post by:
Hereis some basic code that works fine: For Each itm In fld.Items I = I + 1 j = 1 Set rng = wks.Cells(I, j) If itm.Start <"" Then rng.Value = itm.Start j = j + 1
2
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about...
9
by: wparrott | last post by:
I have a table called tblPayScales. It has 5 fields: numRecID - record ID txtCLASSCODE - a 1 or 2 letter text value (A, B, C, BD, L, LT, etc.) numPAYSTEP - a number value 0-49 numSALARY - a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.