I'm new and I REALLY need help

Hi, my name is Chris, I'm new to java.sun.com and I'm a beginner programmer seeking a degree in Comp Sci. I've been writing some code and I've stumbled on some problems that I can't troubleshoot, (run-time?) error seems to be way over my head, the program should work, i don't know why not? Can someone please please give me a clue as to what's going on?
Here's the program;
I have to greate a Coins class that will define the different coins (dime, nickelsk, etc.) that will be used in the main .java file. The main .java file has to randomly generate some "change" and sort it out in the least amount of coins possible.
The problem:
There are no compilation errors; however, when I run the program I receive this run-time error:
Exception occurred during event dispatching:
java.lang.NullPointerException
     at cs130project3.Project3.paint(Project3.java:48)
     at sun.awt.RepaintArea.paint(RepaintArea.java:298)
     at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
     at java.awt.Component.dispatchEventImpl(Component.java:2663)
     at java.awt.Container.dispatchEventImpl(Container.java:1213)
     at java.awt.Component.dispatchEvent(Component.java:2497)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
What does this mean?
Some things I've tried are sticking a g.drawOval() into the paint method, it works just fine, so i assumed there must a problem passing the g object into the coins.draw(g) method, is there a file placement problem or an object passing problem? I'm using Borland JBuilder 7 and i'm assuming that it places the files in the right location, its all in a package called cs130Project3.
Here is the code:
Coins class:
import java.awt.*;
public class Coins {
private final int DIAMETER = 30;
private int coinsAmount = 0;
private String coinsType = "";
private int coinsPosX = 0;
private int coinsPosY = 0;
public Coins(int coinAmount, String coinType, int coinPosX, int coinPosY) {
coinsAmount = coinAmount;
coinsType = coinType;
coinsPosX = coinPosX;
coinsPosY = coinPosY;
public void draw(Graphics screen){
for(int i = 0; i < coinsAmount; i++)
screen.drawOval(coinsPosX,coinsPosY,DIAMETER,DIAMETER);
coinsPosX += 5;
coinsPosY += 5;
if(i == (coinsAmount - 1))
screen.drawString(coinsType,(coinsPosX+10),(coinsPosY+10));
Here is the main class:
import java.awt.*;
import java.util.Random;
import java.applet.Applet;
public class Project3 extends Applet {
private Coins Pennies, Nickels, Dimes, Quarters;
public void init() {
int randomChange = 0;
int numPenny = 0, numNickel = 0, numDime = 0, numQuarter = 0;
String Penny = "1c", Nickel = "5c", Dime = "10c", Quarter = "25c";
Random generator = new Random();
randomChange = generator.nextInt(100);
while(randomChange > 0)
while(randomChange >=1)
while(randomChange >= 5)
while(randomChange >= 10)
while(randomChange >= 25)
numQuarter++;
randomChange -= 25;
if(randomChange >= 10)
numDime++;
randomChange -= 10;
if(randomChange >= 5)
numNickel++;
randomChange -= 5;
if(randomChange >= 1)
numPenny++;
randomChange -= 1;
} // End while loop
Coins Pennies = new Coins(numPenny,Penny,10,10);
Coins Nickels = new Coins(numNickel,Nickel,100,10);
Coins Dimes = new Coins(numDime,Dime,150,10);
Coins Quarters = new Coins(numQuarter,Quarter,200, 10);
public void paint (Graphics g)
Pennies.draw(g);
Nickels.draw(g);
Dimes.draw(g);
Quarters.draw(g);
help me!!
Thank you,
Chris

Chris, I can't even compile your stuff because you didn't post all your classes (Coin is missing), but the runtime error is telling you a lot:
java.lang.NullPointerException
at cs130project3.Project3.paint(Project3.java:48)It says you're dereferencing an object that's null at line 48 of your Project3 class. Turn on line numbering in your text editor, go to line 48, and see what you've missed. One of your objects wasn't initialized. I'll bet you declared a reference type in a class but never initialized it properly in a constructor. The JVM will set those references to null unless you provide a value. - MOD

Similar Messages

  • I recently sold my iphone 4s back to at&t and bought a galaxy s5 but my brother still has an iphone and when he sends me a text it dosnt always go through and i really need help on what to do next please

    I recently sold my iphone 4s back to att and they whiped it clean and now i have a galaxy s5 and my brother still has the iphone but when he sends me texts they dont always go through and i need help on what to do next

    See if this helps:
    iMesssage to old phone
    If you move to another phone and forget to turn off iMessage then read “if you no longer have the device inhttp://support.apple.com/kb/HT5661  If you still cannot resolve it call Apple http://support.apple.com/kb/HE57
    To deactivate iMessage http://support.apple.com/kb/ts5185
    Read http://m.samsung.com/us/support/SupportOwnersFAQPopup.do?faq_id=FAQ00053450&fm_s eq=62995

  • My firefox crashes every 2-5 minutes for unknown reasons. its getting really annoying and i really need help with this :( i cant seem to get an ID on the crash report, its giving a different reason everytime.. i think. please help !

    i have many many crash reports and they all seem different. yet, whenever i search the support pages for help on those crash IDs it shows 0 results. alot of people are having the same problems, and i hope we ALL can get help on this. its getting really frustrating and annoying :(

    i doubt it is from skype. i havent used skype in 2 days or so.
    here are the crash reports IDs from JUST today..
    bp-8c7fab55-79c8-4db1-9527-4ba072111013 10/13/2011 4:51 PM
    bp-db6bf6c4-cf34-4eae-a742-105842111013 10/13/2011 4:51 PM
    bp-f28611cf-3ff0-4658-a843-05da92111013 10/13/2011 4:32 PM
    bp-03fa57ef-580d-4f1d-8fb4-52ac72111013 10/13/2011 4:21 PM
    bp-d07e0d82-df2a-41c8-a19b-bb99e2111013 10/13/2011 4:19 PM
    bp-fafbd8cf-6769-4b76-8153-c17242111013 10/13/2011 4:06 PM
    bp-ee9694ab-585b-4963-8b94-e46432111013 10/13/2011 3:47 PM
    bp-773242e1-a87d-4e19-90cb-ce4e52111013 10/13/2011 3:37 PM
    bp-6bae0db3-895b-4239-8a71-758ce2111013 10/13/2011 3:36 PM
    bp-6dfc1b57-5a8f-4244-baa1-8d0642111013 10/13/2011 3:36 PM
    bp-9a6589cd-0e2f-4299-b517-a6c862111013 10/13/2011 3:31 PM

  • I cant type and use the touchpad, I got this for causal gaming and I really need help.

    If im holding down ANY key the touchpad doesnt work, I have the touchpad on no delay so I can move it right after i stop holding a button, but i cant move and aim at the same time, please help!

    Hi there ,  Thank you for visiting the HP Support Forums and Welcome! This is a great site to get answers and ask questions. I read your post on the HP Support Forums and wanted to answer your post. I understand that you cannot use the Touchpad and the key functions at the same time.  Here is a document on how to troubleshoot the mouse and Touchpad gestures. In the document, it shows you how to change the settings by clicking the settings icon to adjust the button actions on the Touchpad. Sometimes this is caused by an update that is needed. Here is a link to the HP Support Assistant. Just download and run the application and it will help with the software and drivers on your system that might need updating. Please let me know how this goes. Thanks

  • A photoshop beginner - Bridge crashes and I really need HELP!

    Hi there,
    I am a complete beginner with Photoshop and I am using this as part of a hobby. Any feedback would be greatly appricaited, however, I don't quite understand some of the things I'm reading.
    My Adobe Photoshop CS6 extented is working fine.
    The problem I have is with Adobe Bridge CS6. I can load the programme but as I go to open a file it will say "Adobe Bridge CS6 has stopped working. Windows is checking for a solution to the problem" then follows "Adobe Bridge CS6 has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
    I installed Photoshop CS6 yesterday and it started out fine... I had used Camera Raw once or twice and then since, it has continued to say this.
    How do I get this problem fixed? Is there any other way I can open Camera Raw?
    Thank you.

    first you might benefit from reading [Time Machine 101|http://support.apple.com/kb/HT1427].
    as for step by step...
    1. first you need to decide how big you want to make the partitions for SD and TM. SD partition should be big enough to contain a full backup of your main HD. You should leave a bit of overhead though (at least 25%).
    TM partition should be at least 2-3 times bigger than the total amount of data you want to back up.
    2. partition your Lacie drive. start Disk Utility, select the whole lacie drive (the model not the name) and click on the partition tab. select the volume scheme (2 partitions in your case) and drag the slide in the middle up or down to adjust the partition sizes. select Mac OS extended journaled for format. click on options and select the partition map. choose Apple partition Map for a PPC mac and GUID partition table for an intel one.
    finally click apply and wait for the partitioning process to finish.
    3. click on the TM button in the dock and follow the instructions. those are very simple. the only thing you'll have to do is choose the drive to be used for TM backups.
    that's it for TM. The first backup will take a long time so be patient.
    4. using superduper! is very easy too. start SD, select the target and the destination drive and click "copy now". don't run the SD and TM backups simultaneously. wait for the first TM backup to finish before starting with SD.

  • Hi i am paying for the photoshop and i can't use and download it and i really need this app for my art exam which is on wednesday please help me, hi i am paying for the photoshop and i can't use and download it and i really need this app for my art exam w

    i need some one to help me  for downloading photoshop on my mac and i am already paying monthly for it but i can not use it  and i really need help because i need photoshop for my art exam which is on wednesday

    What is the problem your having downloading the creative cloud desktop application then using it to download and install Photoshop.  You can try the direct download if you want to bypass the creative clod desktop application install. Still it mad be installed if you use the direct installer.  Pleas read the download instruction and follow them else you will be denied access.  Adobe CC 2014 Direct Download Links: Creative Cloud 2014 Release | ProDesignTools

  • I have an iPod Nano 7th generation, and I keep getting an error saying that iTunes could not recognize my device. I have tried nearly everything,except I don't have admin rights on the computer, and really need help.

    I've tried a lot to get it to work, even using a new charger and putting it into Disk Mode. I really need help. Can anyone give me some advice? Thanks.

    Hi Dawson777,
    Thanks for visiting Apple Support Communities.
    It sounds like you're receiving the message "An iPod has been detected, but it could not be identified properly" when you connect your iPod nano to your PC. You have tried some good troubleshooting steps already, and you may want to review the additional steps in this article:
    iPod nano: Error message saying that iPod 'could not be identified properly'
    http://support.apple.com/kb/ts3218
    Best Regards,
    Jeremy

  • My Iphone 4 goes off after tried to instul ios 7.0. I 'm onlu seeing the sing of iTune and USB plug right on the phon's  screen. I really need help because I all i got

    My Iphone 4 shuted down after tried to instul ios 7.0. I 'm only seeing the sing of iTune and USB plug right on the phon's screen
    I really need help because that's only phone i got.

    Just back from Genius Bar and two other people at my table had the same problem. Their 4Ss aren't charging either. One of them had a fried board according to the tech. At least my HW checked out OK. It just won't charge.
    The tech tried to tell me that it was because my connector was corroded, which I told him was kind of a weak argument since evidence points to that the update has something to do with it.
    They're seeing a lot of these and it looks like they already have a script.
    Luckily I had enough juice left to recycle it for like $180, so I picked up a 5S with a new 2 year.
    It looked to me like this is going to blow up pretty big. Like class action lawsuit big.
    If you have an iPhone 4 or 4S, and you haven't updated it to iOS 7, don't for now. See if a patch comes out that doesn't brick your phone. Or get an induction charger maybe? Don't just update and expect absolutely no problems because too many people are having problems right now.

  • DOES ANYONE KNOW HOW I CANT DELETE MY APPLE ID I JUST GOT A NEW AND NO LONGER NEED THE OLD 1 HELP PLEASE

    DOES ANYONE KNOW HOW I CANT DELETE MY APPLE ID I JUST GOT A NEW AND NO LONGER NEED THE OLD 1 HELP PLEASE

    As far as I know they can't be deleted, just remove any personal info from it (credit card details etc) and stop using it.
    If you downloaded any content via it then you will need to remember it and it's password, as content is tied to the account that bought/downloaded it, so if you move to a new computer you'll need to authorise the account on it if you want to use any of its content there (or if you bought apps with it you'll only be able to download updates to them via that account)

  • Hello, i really need help. I had just updated my iphone 3gs to 6.0.1, and after I updated, it won't activate.

    Hello, i really need help. I had just updated my iphone 3gs to i.o.s. 6.0.1, and after I updated, it won't activate.I tried it in itunes and it always says " We cannot activate your iphone at this time..." and when I activate using Wi-Fi, it says, "Your iPhone cannot be activated because the activation server is temporarily unavailable." I could swear that my Wi-Fi is fine, and my Itunes is on the latest version.  Is this a bad thing or does this normally occurs? Can I still fix this ? I'm so desperate to use my iphone cause I use it everyday for personal purposes. I sure would appreciate any tip or help . PLSSSS ! Thank you for that wonderful being that can help.

    Do not take it to a third party repair shop - downgrading causes problems and voids your warranty.
    I had to unlock it so that i could really use it as a phone.
    And that is the root of the problem. Unless you had your carrier unlock it, it was hacked and cannot be legitimately activated. Even if you don't care about warranty or problems, downgrading simply will not help an activation issue.

  • In testing 9 and X, "Compare Docs" we have a critical issue and really need help!

    For years we have used Acrobat 7 to do PDF compares and we love it!  However, the company recently advised we must upgrade to 9 and then eventually to X.  In testing 9 and X, Compare Docs we have a critical issue and really need help.  Our PDFs are produced by IT in a batch process and one of our main, critical functions is to compare previous PDFs to current PDFs;  however, in using 9 the Compare screen automatically sets the Doc Description for our PDFs to "Scanned Doc" and does not produce any differences! If you try to change the setting to Reports --it totally shuts down both documents without running!  Version 7 runs the compare of the same PDFs  beautifully, pointing out all the differences, as usual!  Has this every happen to anyone?  Do you know what we can do to our PDFs to allow version 9 to do the compare and produce results?  Why is 9 treating these non-scanned PDF docs as such?  Thanks so much for any help or insight you can give me on this issue! 

    (Moved the discussion to the correct forum)

  • Ok, i have lost my ipod and i REALLY need to find it, and i have no idea how i can track it. HELP!!!!

    ok, i have lost my ipod and i REALLY need to find it, and i have no idea how i can track it. HELP!!!!

    There is no way to track a lost or stolen iPod Classic. Sorry.
    Reporting a lost or stolen Apple product
    B-rock

  • I really need help on reseting my security questions i tried sending in my rescue email but the rescue email is not showing up on the password and security tab and i'm positive i don't know the answers this is really getting annoying _

    i really need help on reseting my security questions i tried sending in my rescue email but the rescue email is not showing up on the password and security tab and i'm positive i don't know the answers this is really getting annoying

    If your rescue email is not working and you cannot remember even one answer, then you only have one option - call Apple.
    http://support.apple.com/kb/HT5665

  • Hello. My mac can't connect to my time capsule. There is no response and I can't put it back to the originals definitions because all my files are there and I can´t loose them. (sorry about my bad english, but I really need help!)

    Hello. My mac can't connect to my time capsule. There is no response and I can't put it back to the originals definitions because all my files are there and I can´t loose them. (sorry about my bad english, but I really need help!)

    Your files are unaffected by a reset.. no reset via the reset button on the TC harms, deletes or does anything to your files.
    The Factory Reset universal
    Unplug your TC/AE. Hold in reset. and power the TC/AE back on..  all without releasing reset and keep holding in for about 10sec. The time is not important.. it is the front LED rapid flashing that indicates you are in factory mode.
    Release reset.
    If it doesn’t flash rapidly you have released reset at some point and try again.
    Be Gentle! Feel the switch click on. It has a positive feel..  add no more pressure after that.
    TC/AE will reboot after a couple of minutes with default factory settings and will wipe out previous configurations.
    No files are deleted on the hard disk.. No reset of the TC deletes files.. to do that you use erase from the airport utility.
    Here is how to do a fully manual setup for TC which is sometimes necessary with Mavericks in particular.
    Airport Utility shows "unexpected error - please try again" when connecting to Time Capsule

  • PLEASE HELP ME.  Some important emails have gone to an archive mail box and i really need them.  Can someone please help me with how to view the archive email box and the emails that are in there?

    PLEASE HELP ME.  Some important emails have gone to an archive mail box and i really need them.  Can someone please help me with how to view the archive email box and the emails that are in there?

    http://kb.mozillazine.org/Recovering_deleted_mail_accounts

Maybe you are looking for