DAMN NullPointerException !! How do i get rid of it?

Hi,
My code compiles perfect, but when i run my program i get a "NullPointerException". I spent way too long and dont think I'll ever figure it out. Im hoping somebody can see whats wrong. It happens when I try to assign values to my array of objects. here is my code, thanks!!
Here is the code for PointObject.java:
public class PointObject {
        int reference;  //the class number this point references
        int xc;         //the x coordinate
        int yc;         //the y coordinate
    public PointObject() {
        int reference = 0;
        int xc = 0;
        int yc = 0;
}Here is the code for Jtrack.java:
public class Jtrack extends Frame {
        PointObject[] po;
        public class DPanel extends Panel {
                public DPanel() { }
                public void paint(Graphics g) {
                        super.paint(g);
                        g.setColor(Color.black);
                        Random r = new Random ();
                        for (int k = 1; k <= number; k ++) {
                                int x = r.nextInt (getWidth() - 50);
                                int y = r.nextInt (getHeight() - 50);
                                g.drawRect (x, y, 50, 50);
                                g.drawString(""+k,x+15,y+15);
                                setPointObject(k-1, k, x, y); //#problem on this line#
        public void setPointObject (int idx, int ref, int x_c, int y_c){
                po[idx].reference = ref;
                po[idx].xc = x_c;
                po[idx].yc = y_c;
        public static void main (String[] args) throws Exception {
                new Jtrack ();
}

did you size and instantiate the points instances correctly
that you are assigning to if not that is the problem.
if you did then its probably be in your loop
a alternate way to check your loop is to place a conditional
check in thier just before the line that errors out like so
public void setPointObject (int idx, int ref, int x_c, int y_c){
if(po.length <= idx){
System.out.println(" idx element being assigned is "+idx+" however po.length is "+po.length );// that way you can at least figure it out
po[idx].reference = ref;
po[idx].xc = x_c;
po[idx].yc = y_c;
}

Similar Messages

  • NullPointerException, how do i get rid of?

    Hey guys,
    I'm totally puzzled by this one. All i'm trying to do is to change the content of JTextField(), but every time i do i get a NullPointerException. Here's the code:
    public class PrivateMessageWindow extends JFrame
        private  Container container;
        private  JTextArea textArea;
        private  JTextField inputField;
        private  String windowId, messageDestination;
        private  Message m;
         public PrivateMessageWindow(String Id)
               super("Private Message");
               Container container = getContentPane();
               JTextArea textArea = new JTextArea();
               textArea.setEditable(false);
               JTextField inputField = new JTextField();
                //ActionListener for inputField
               ActionListener k = new PrivateWindowListener();
               inputField.addActionListener(k);
               //Placement of element on Panel
               container.setLayout(new BorderLayout(5,5));
               container.add(textArea, BorderLayout.CENTER);
               container.add(inputField, BorderLayout.SOUTH);
               //Initializes a message of type private Message
              setSize( 300, 150);
              setVisible(true);
          }//end of constructor
           private class PrivateWindowListener implements ActionListener
                   public void actionPerformed(ActionEvent event)
                        inputField.setText("");
    }// end of  private class PrivateMessageWindowThe problem occurs anytime i access a variable outside the actionPerformed method i get a NullPointerException. I'm not sure if it helps but this class gets triggered by a JButton object.
    any clue of wats happening here?
    Tanx.

    You are not initializing your JTextField inputField. Instead, you instantiate a local variable. The same applies to your JTextArea. You should have:textArea = new JTextArea();
    textArea.setEditable(false);
    inputField = new JTextField();Moreover, I don't think you really need the field container.

  • My default search engine is Google and I deleted Bing. Whenever I open a new tab, Bing is displayed and it takes the focus so if I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING?

    My default search engine is Google and I deleted Bing from the Search Providers. Facebook is set as my home page. Whenever I open a new tab, a Bing search box is displayed on the page and it takes the focus so when I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING

    Swarnava, thank you very much! that did it and I am Bing-less . . . OH HAPPY DAY!! WOOHOO!!!! thank you, thank you, thank you!

  • Something called My Start has just appeared and it screws up everything. How can I get rid of it?

    When I installed Firefox on my new computer, it came with a new thing called incredimail and My Start. It screwed up everything, making it impossible to restore my settings. I deleted Incredimail using the Control Panel but My Start continues to upload everytime I open Firefox. I can't find it in my list of programs or in my program file on my C drive. How do I get rid of the damn thing? Jim MacNeill

    After uninstalling Incredimail (free) on my laptop, I also couldn't get rid of the MyStart search option. Waste many hours. Easy answer... Firefox home page... Firefox drop down menu on upper left... select help... select troubleshooting information... click on Reset Firefox! Voila! Problem gone!

  • How do i get rid of the Yahoo Virus?

    Everytime i type something in the adress bar and hit enter i get redirected to yahoo search.
    I KNOW THIS HAS BEEN ASKED MANY DAMN TIMES.
    But the solutions suggested DO NOT WORK, because the keyword.URL does not exist anymore.
    I've had the same problem 2 weeks ago and yesterday i've let a friend install Spotify on my computer and BOOM - this morning guess who was back.
    The last time I had to remove it i had to reinstall everything which resulted in having me to input all the pages i frequently use by hand aswell as the corresponding log ins.
    I don't wonna go through this trouble again.
    How do I get rid of it and more important is there a way to banish the Yahoo Virus forever without having to gamble everytime you install a new piece of software?

    The reason keyword.URL no longer matters is that the address bar is designed to use the same search engine you select on the Search Bar (by default, Google).
    If that is not working, check your extensions. You can review, disable, and often remove them on the Add-ons page. Either:
    * Ctrl+Shift+a
    * orange Firefox button (or Tools menu) > Add-ons
    In the left column, click Extensions. Then, disable everything nonessential or unknown -- often you won't even recognize everything here.
    Usually a link will appear above a disabled extension to restart Firefox. You can complete your work on the add-ons page and click the link as the last step.
    To clean up non-default settings, you can use the Search Reset extension:
    https://addons.mozilla.org/en-US/firefox/addon/searchreset/
    Any luck?

  • When I login on my When I sign in to a site on my ipad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    When I sign in to a site on my iPad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    You can edit keyboard shortcuts in Settings>General>Keyboard>Shortcuts>Edit.

  • I have a Australian iTunes account and want to switch to using the u.s store as I now live there, I cannot do this because I have $1.41 still in the oz account an image to have a zero balance to change stores, how can I get rid of the $1.41?

    I want to switch to the u.s store as I now live in the us, I cannot switch stores because my balance is $1.41 in the oz store and needs to be zero, how can I get rid of the $1.41 when everything costs more or less than that? I do not have a credit card on the oz iTunes account an I cannot use my us one to top it up.
    HELP

    Click here and request assistance.
    (60992)

  • I want to switch stores from Japan to USA. I used to have an iTunes card, and there's 15 YEN left in my account, how can I get rid of that so I can start purchasing in the US store using my new credit card?

    I want to switch stores from Japan to USA. I used to have an iTunes card, and there's 15 YEN left in my account, how can I get rid of that so I can start purchasing in the US store using my new credit card?

    I can't seem to find an app that costs my available balance. iTunes said I need to spend it ALL before I can change stores. This means I cannot totally change stores.... Hopeless.

  • Since downloading ios5 on my iphone 4 the capacity guage in itunes shows other as over 21Gb and i can no longer fit any music on it. How do I get rid of the other stuff? other

    Since downloading ios5 on my iphone 4 a few days ago, the capacity guage in itunes shows "other" as over 21Gb and i can no longer fit any music on my iphone.
    How do I get rid of the other stuff?
    capacity available on 32 Gb iphone is 28.49Gb
    i previously had 21.97 Gb music, over 6 Gb photos, about 1Gb of apps, and minute amount of audio
    now i have no music, 5.4 Gb photos and similar (0.8Gb) for  apps and audio. i have deleted heaps of photos and unused apps to try to make space but obviosly this is a much bigger problem. I also created a smaller music folder on itunes to sync to but at present no music is selected for syncing due to the lack of available space.
    i have 15Gb icloud account now also which is about half full.
    Ive done a little research and heard similar tales but with much smaller other totals than this. Can you help?
    i cant update my apps as i get a message saying i do not have enough available space.

    I had the same problem today and was able to resolve it without having to do a restore or reset. The problem had something to do with my mail accounts. The upgrade reset my mail settings, switching both my gmail and my .mac mail to "archive all mail". I went into the General Settings, disabled that setting, and resynced the phone. The "other" storage allottment dropped back down to less than a gig.
    Before you restore or reset, I would try that first.

  • I transferred data from my external hard drive to my restored Mac Book Pro via migration assistant and now my external hard drive in time capsule has red minus signs. How do I get rid of that without getting rid of any of my data?

    I used Migration Assistant to transfer my data from my external hard drive via Time Capsule to my restored Mac Book Pro. When I now go into Time Capsule I there are red minus signs in the corner of all the folders that are contained in my back up. How do I get rid of this and access my previous back-ups?

    Select the drive and Finder > Get info and at the bottom "ignore permissions on this volume"
    You can copy the files, but the ownership on the files still belongs to the other user account, once your done copying, then perform a #6 Reset Users Permissions and that will set all the ownership to that account.
    ..Step by Step to fix your Mac
    Another method is to copy the entire folder, then change it's permissions.

  • I deleted an audiobook from Itunes on my computer and emptied my trash, plugged in Iphone 5s to sync Itunes. Audio book still appears on my Iphone. How do I get rid of audio book on Iphone?

    I deleted an audiobook from Itunes on my computer, emptied my trash, they attached Iphone 5s to computer to sync computer to Iphone thinking that by deleting the audiobook from Itunes, the audiobook would then be deleted from my Iphone.  It's still on my Iphone.  How do I get rid of the audiobook on my phone?

    JustinV72 wrote:
    How do I get the audiobook onto my iphone without erasing anything?
    You transfer the purchases to the computer you use to sync the iPhone.  You can use a thumb drive or an external HD, etc.  Read this: iTunes for Mac - How to copy purchases between computers:  http://support.apple.com/kb/HT1373

  • Some of my songs are listed twice on my iPod itself.  However, when I plug the iPod into my computer, the songs don't show up twice in iTunes when I click on device/music. How do I get rid of the duplicate songs on my iPod?

    Some of my songs are listed twice on my iPod itself.  However, when I plug the iPod into my computer, the songs don't show up twice in iTunes when I click on device/music. How do I get rid of the duplicate songs on my iPod?

    that is odd! that should not be happening.
    Are you syncing your songs right off of itunes itself? because it should be syncing over to the ipod however it is listed in itunes.

  • How do I get rid of the Firefox disc icon on my desktop?

    Just updated Firefox... the disk icon shows up on my desktop every time I open the application, as does a window telling me to put Firefox in my applications folder, which I've already done. How can I get rid of these? Thanks!

    If  you have not tried this already, try this.
    System Preference > Notifications
    Select Calendar and uncheck the  box beside "Badge app icon".

  • How do I get rid of the /welcome subdomain address from my website address?

    My website cobbity.com redirects to cobbity.com/welcome when opened on home page, how can I get rid of this problem?
    thanks in advance

    Why is this a problem? It is perfectly normal - Welcome is the very first page of your website, so when someone enters your url, it will go to the first page of your site which happens to be http://www.cobbity.com/Welcome.html.
    My own site is the same - my first page is welcome and when someone types in my url it goes to http://www.domain.com/Welcome.html. Normal.
    Where are you publishing to? MobileMe or an external server such as GoDaddy? If MMe, then you can change the way in which you link your domain name to your site - rather than using CNAME forwarding, change it to masked web forwarding. If you use this, then you forward your domain name to web.me.com/username/sitename and all that you will then see is http://www.domain.com for every single page if this is what you want?
    Only problem with this is that people cannot bookmark individual pages of your site, just the whole site.

  • How do i get rid of cover flow in music on my 4s

    how do you get rid of cover flow off on the 4s and go back to play list

    Cover flow appears when your phone is rotated in landscape position (sideways).  Rotate it back to portrait position (upright) to return to the song list.

  • How do I get rid of the 1/16" space between my igoogle homepage and firefox ribbon?

    I am currently running Firefox 4 and have igoogle set as my homepage. Both with the previous version of Firefox and with the new one I have about a 1/16 inch blue gap/space between the top of my igoogle homepage and the bottom of the Firefox ribbon/header. How do I get rid of this eyesore? It is only when I am on my igoogle homepage that this is a problem. All other pages are seamless.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    Do a malware check with some malware scanning programs on the Windows computer.<br />
    You need to scan with all programs because each program detects different malware.<br />
    Make sure that you update each program to get the latest version of their databases before doing a scan.<br /><br />
    *http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
    *http://www.superantispyware.com/ - SuperAntispyware
    *http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
    *http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
    *http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
    See also:
    *"Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked

Maybe you are looking for

  • Font problem in xfce

    Hi All, I'm having a problem with fonts in certain applications in XFCE (doesn't happen when I use openbox).   For example, here's what chrome looks like: I'm sure it's something simple like a missing font, but I'm not entirely sure how to fix it. Ha

  • Required Config and testing Docs for cash management/cash forecasting

    Hi All, My client need to implement cash management/cash forecasting .. Can anyone send the details Required Config and testing Docs for the same as earlier i have not worked in this area.. Thanks in advance... Regards, Sandip

  • Reusability of web dynpro callable object

    Hi, I want to use same webdynpro callable object inside another callable object including some extra input and output parameter. So that I dont have to write the same code again in another callable object. is it possible?

  • CacheComponent not registered (KEY=FLEXFIELD_METADATA_CACHE) (APP=FND)

    Hi, I am doing an extension of VO in iSupplier portal and there is a flow consisting of 3 pages to complete a task for creating an invoice from the PO. I have done the extensions required in the local jdev and till the 3rd page in the flow everything

  • How to transfer audio to USB - with folders?

    Hi, Using ITunes 10.6.3.25 As subject says, I know that I can drag the content of a playlist to my USB stick, however, that just copies all files to the root of the USB drive. It does not place the music in folder of any kind. Even a small playlist w