Why this NullPointerException??

In this simple code i try to appear some buttons
but give me nullpointerexception why ??
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JFrame {
    private final static String[] buttonNames = {"beshoy", "atef", "william"};
    private JButton[] buttons;
    private JPanel panel = new JPanel(new FlowLayout());
    public Test() {
        createButtons(buttonNames);
        panel.add(createButtons(buttonNames));
        getContentPane().add(panel, BorderLayout.CENTER);
    public static void main(String[] args) {
        Test test = new Test();
        test.setDefaultCloseOperation(Test.EXIT_ON_CLOSE);
        test.setSize(new Dimension(600, 300));
        test.setLocationRelativeTo(null);
        test.setVisible(true);
    private JButton createButtons(String[] buttonNames) {
        int i;
        buttons = new JButton[buttonNames.length];
        for (i = 0; i < buttonNames.length - 1; ++i) {
            buttons[i] = new JButton(buttonNames);
return buttons[i];
thanks in advance
Beshoy Atef                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

when I do this :
    private JButton createButtons(String[] buttonNames) {
        int i;
        buttons = new JButton[buttonNames.length];
        for (i = 0; i < buttonNames.length ; ++i) {
            buttons[i] = new JButton(buttonNames);
return buttons[i];
}it give me :  java.lang.ArrayIndexOutOfBoundsException: 3
why??
when :
button[0]>> it will has buttonNames[0]>> beshoy
button[1]>> it will has buttonNames[1]>>atef
button[2]>> it will has buttonNames[2]>> william
please illustrate answer with code
thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Please help in this NullPointerException Error

    Please help as to why I am getting this NULLPOINTERException
    public class TestHarness {
         public static void main(String[] args) {
              TestHarness th = new TestHarness();
              th.t();
         public void t(){
              HashMap<String, Integer> colMap = new HashMap<String, Integer>();
                                    colMap.put("TRADE_KEYWORD.Strategy", 1);
                                    String reportRow[] = null;
                                     String strat = reportRow[colMap.get("TRADE_KEYWORD.Strategy").intValue()];
                                     System.out.println(strat);
    }

    you do
    String reportRow[] = null;then wonder why you get an NPE when you try to access reportRow?
    Think! You have to define reportRow (as something other than null) before you can use it! It's not that hard to understand.

  • Help me decipher this NullPointerException

    I've done all that I can to figure out why I'm getting this NullPointerException.
    Thanks in advancd for your help.
    Jason
    Here is were I'm calling the class from:
    SpellDictionary dictionary;
    //bunch of code .....
    public void test(){
         boolean foo = dictionary.isCorrect("word");
         System.out.println(foo);
    Here is the complete class I'm calling:
    package com.swabunga.spell.engine;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    public class SpellDictionary {
         private Transformator tf = null;
         * Returns the code representing the word.
         public String getCode(String word) {
              tf = new DoubleMeta();
              return tf.transform(word);
         * Returns true if the word is correctly spelled against the current word list.
         public boolean isCorrect(String word) {
                   System.out.println("isCorrect");
                   String words;
                   try {
                   URL url;
                   URLConnection urlConn;
                   DataOutputStream dos;
                   url = new URL("http://jason.governet.net/spelling/check.cfm?word=" + word + "&soundex1=" + getCode(word));
                        System.out.println(url);
                   urlConn = url.openConnection();
                   urlConn.setDoInput(true);
                   urlConn.setDoOutput(true);
                   urlConn.setUseCaches(false);
                   urlConn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
                        // the server responce
                   BufferedReader dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                   words = dis.readLine();
                   dis.close();
              catch (Exception ex) {
                        System.out.println("check word error ");
                        System.err.println("SpellChecker error: "+ex.toString());
                        ex.printStackTrace();
                        return false;
              //LinkedList possible = getWords(getCode(word));
              if (words.trim().equals("1"))
                   return true;
              return false;

    Also, next time, please format your code (see the link that says "Formatting Help" right above the message entry box), and please be more specific. You left out where you were getting the exception, and possibly the very code that causes it--or, if I guessed right, the code where lack of an additional line of code is causing it.
    The more relevant information you provide, the easier it is for people to answer your question. Notice the emphasis on relevant. Pasting in all of your code doesn't usually help a whole lot. Sometimes, taking the time to think about what's relevant, and how to best explain your problem without piling on tons of useless information, will allow you to solve the problem without even posting here.
    </rant>
    That's not directed just at you. It's also another general venting at the many poorly thought out questions posted here.

  • Can't figure out this NullPointerException

    Hi I posted yesterday that I was making an infix to postfix converter for school and I thought I had it finished and all good when i compiled a testapp for it and got this:
    Exception in thread "main" java.lang.NullPointerException
         at myStack.push(myStack.java:14)
         at inToPost.translate(inToPost.java:14)
         at itpTest.main(itpTest.java:5)Here is the code that is creating this error:
    Method Push in myStack:
    public void push(String str)
              Node newTop = null;
              newTop.item = str; // Line 14
              newTop.next = top;
              top = newTop;
         }method translate in inToPost
    public void translate(){
              String token;
              inFile.open("data.txt");
              while(!inFile.eof()){
                   token = inFile.readString();
                   token.trim();
                   if(token.compareTo("open") > 0){
                        theStack.push("open");  //Line 14
                   else if(token.compareTo("close") > 0){
                        gotRightPar(token);
                   else if(token.compareTo("plus") > 0 || token.compareTo("minus") > 0){
                        tokenIsOp(token, 1);
                        break;
                   else if(token.compareTo("times") > 0){
                        tokenIsOp(token, 2);
                   else if(token.compareTo("pow") > 0 || token.compareTo("goob") > 0){
                        tokenIsOp(token, 3);
                   else
                        output = output + " " + token;
              inFile.close();
         }Can someone give me some insight on maybe why this is happening.
    I read the API on this error but I don't see why I would have a problem.
    As always thanks in advance for the help!

    You're a total dumb ass:
    public void push(String str)
              Node newTop = null;  // newTop is null
              newTop.item = str; // Line 14; it's still null here.
              newTop.next = top;
              top = newTop;
         }Set newTop to point to a non-null Node.
    %

  • I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

  • My Macbook pro is rejecting my Iphone 5 charger. When ever I plug it in it says that the usb is taking to much power, yet when i plug in a different Iphone 5 charger it works fine. I'm just wondering why this is happening and how to fix it?

    My Macbook pro is rejecting my Iphone 5 charger. When ever I plug it in it says that the usb is taking to much power, yet when i plug in a different Iphone 5 charger it works fine. I'm just wondering why this is happening and how to fix it?

    My Macbook pro is rejecting my Iphone 5 charger
    Do you actually mean the white cable with a lightning plug on one end and a USB on other
    If so that is not the charger ,that is the cable
    The charger is the device that plugs into the mains socket
    If so
    cable may be faulty if less than 12 months old take it to Apple Store genius bar for checking

  • Not Sure why this is not working

    hi all,
    Version details :
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Solaris: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Select * From Dual
    Where 'A' In (Decode( 'A','A','''A'''
      ||','
      ||'''B''','C','C'));
    Result :
       no rows
    Select * From Dual
    Where 'C' In (Decode( 'C','A','''A'''
      ||','
      ||'''B''','C','C'));
    Result :
    Dummy
       XPlease let me know why this is working like this ..
    Problem:
    When the input is 'A' then condition should be 'A' in ('A','B')
    When the input is 'C' then condition should be 'C' in ('C')
    Thanks,
    P Prakash
    Edited by: prakash on Feb 4, 2013 10:41 PM

    Your first query
    Select * From Dual Where 'A' In (Decode( 'A','A','''A'''||','||'''B''','C','C'));This would be evalueated like this
    select * from dual where 'A' = '''A'''||','||'''B'''And your second query
    Select * From Dual Where 'C' In (Decode( 'C','A','''A'''||','||'''B''','C','C'));Thiw would be evaluated like this
    select * from dual where 'C' = 'C'You cannot pass value for IN operater as comma seperated string. The entire string will be passed as a single value. Each value in an in operator is a seperate variable and need to be passed sperately.
    select * from dual where 'A' in ('A', 'B') is not the same as
    select * from dual where 'A' in ('''A'''||','||'''B''')

  • In my Macbook Pro, on a few occassions, the apple menu bar blacks out. its displayed as a negative image. The desktop wallpaper get greyed out and i get a blank screen as wallpaper. No idea why this happens. I reset the system and issue gets resolved.

    In my Macbook Pro, on a few occassions, the apple menu bar blacks out. its displayed as a negative image. The desktop wallpaper get greyed out and i get a blank screen as wallpaper. No idea why this happens. I reset the system and issue gets resolved.

    AshwinVC wrote:
    I reset the system and issue gets resolved.
    How? 

  • Why this new version of iTunes doesn't have Album Art or It didn't show up?

    Why this new version of iTunes doesn't have Album Art or It didn't show up?
    Also, in my iPod Touch 4th, it erase all album art from my iPod, then i tried to put again a new Album Art, ...download again from the image sites and still ...it didn't show up.? What a waste!
    I waste all my time to set all album art on my iPod, then it just gone. kindly pls fix this issue. hate this new version of iTunes, so complicated.
    The first thing i saw after i install new version of iTunes, it showed only music files. I don't know where to look for the old version of Sidebar. I keep on trying to look for it where I can see or any sign off button just to show up this stupid SideBar. Also, why i couldn't find? The "Menu Bar" is also hide!
    Until i found out in "View" tab. Then i saw the Show Sidebar. Question? why do you need to hide that Side Bar? For what?. it is so so so complicated specially to those people who can't relate for this. (Also the button (from previous iTunes) to show the Album Art, now it's gone. I check every Tab, but there's no way to see the Album Art.)
    Another comment. I download also some of my songs to my iPod, I wasted my time to collect all of my favorite music files. Also some are came from CD's and friends. I had all that favorite music in my iPod. Then the version iOS 5.+ came then I updated my iPod, another options to save files (iCloud) but I think there are something that I MISS about updating my iPod. Then suddenly I checked my iPod... all music (with Album Arts) are gone. All Apps are Gone. Videos as well.
    If you don't know how to use that iCloud (with only 5GB storage), you'll gonna miss/lost everything.
    Then I start all over again, i still have my BACK UP, good to have that. Now it's all set until I update the latest iOS 6. And another version of iTunes.
    Then I realized my computer getting slow. I uninstalled it. My laptop started to work fast again. Then I download again the iTunes. So now I know, it has the ability to slow my computer. Everytime I turn on my iTunes, it hang. (Not Responding). Solution... CTRL+ALT+DELETE. Then every second time to open the iTunes, and it works. (it means, to open iTunes, need twice)
    Then suddenly my laptop is not working. All my files has been corrupted. My Hard drive doesn't work properly. Now I don't have any stupid BACK UPs. My music files usage is 18 GB, only contacts, documents, notes, or some other files that can only fit to your "iCloud" not my 18GB music files and other photos. Your solution is to BUY more storage. Another COST! Another wasting time to set everything then need to pay more?
    If you let your unit (iPod,iPhone,iPad) to export music to PC, or any mini SDcard to use as storage, it won't happen.
    There is another....
    It has Bluetooth, right?
    Use less! Doesn't work. There's no way to use it.
    All I need is to install an application to use your bluetooth. (for same unit or Apple unit only). And pictures only can send via Bluetooth if you an application.
    Even if you go to "Photos" check if there's a way to send pictures? there is no way to send via Bluetooth, even Photos, Songs.etc. It can't even share some other friends (even they have own iPad, iPod, iPhone or same products) who has a unit with Bluetooth.
    And the last.. only one port. there's no way to watch videos through HDMI. No HDMI port, no SD or any card slot. Must to buy their products.
    Very costly!
    I know (like iPod) it's very friendly to use it, but you  must spend more money first before it can use.

    Yes, the old album art view is gone, bu you can see the album art for a song that's playing by clicking on the art image and it will open a bigger view.
    Everything else in your post is a waste. I'm not going to spend time reading it. If - and I repeat if, you have a question on how to get the best out of the new look iTunes, post it. But don't spend your time in long rambling negative rants.

  • Dear Ms. Qaya Ltfabh help me. I do not know why this is a problem that has been part of Russian Tvlbarmn(mozila firefox). What I Brgrdvnmsh Vnmydvnm again in En

    Dear Ms. Qaya Ltfabh help me. I do not know why this is a problem that has been part of Russian Tvlbarmn. What I Brgrdvnmsh Vnmydvnm again in English. Bkhvahydmytvnm send a screenshot if I tell you to see exactly my problem. Thank you
    I also say that in English I dont know if Nmdarm Mykhvahydbh help me help in the form of a video file or image...Anglysym your friends know I'm so weak, so therefore the description Vsvalattvn noticed something. If you have software that will solve my problem please let me download it, I probably am

    I don't understand what question you are trying to ask. Can you restate the question?

  • My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    I have worked my way through the assistant and nothing works. I have tried connecting in disc mode but although the screen on the ipod is showing that the device is charged and that it is in disc mode as soon as I connect it to the computer it comes up with the error message 'please wait very low battery' and stays like that until I disconnect when it appears to be OK again. I have tried on both pc and mac.
    BTW the ipod is an ipod video not classic if that makes any difference.
    Thanks

  • When I compose an email in either gmail or yahoo, the cursor lags behind for about 2 seconds. This does not happen when I compose an email with Safari or Chrome. I am using a Mac with Firefox version 3.6.3. Any idea why this happens?

    When I compose an email in either gmail or yahoo, the cursor lags behind for about 2 seconds. This does not happen when I compose an email with Safari or Chrome. I am using a Mac with Firefox version 3.6.3. Any idea why this happens?
    == This happened ==
    Every time Firefox opened

    try
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • How can you expect the customer to have a LOCAL/COUNTRY Based Credit Card every where we go??? Last week I was on holiday in HK,  and  from my Hotel I was able to use m VN Credit Card with my Apple ID and purchase online!  Why THIS WEEK, can't I use my HS

    Apple_ID_card_declined_for_this_country
    How can you expect the customer to have a LOCAL/COUNTRY Based Credit Card every where we go???
    Last week I was on holiday in HK,
    and
    from my Hotel I was able to use m VN Credit Card with my Apple ID and purchase online!
    Why THIS WEEK, can't I use my HSBC Platinum Credit Card from Vietnam,
    for my Singapore Apple ID account ,
    while working here in Vietnam???

    Unfortunately, this is a problem that is driven by the DRM Dictatorship.  Despite the proliferation of mobile devices and the fact that there are many of us who do a lot of international travel, content providers don't want you to have access to their products outside of your homeland.  The Balkanized mentality of the DRM Dictatorship is way out of touch with the modern world.
    At least Apple, to its credit, allows you to use your accounts outside of your homeland as long as you have the proper credentials for them.  Most other services use the more Draconian geolocation filtering which does require you to be physically present in your homeland.  For the most part, you are not allowed to leave home if you want access to your favorite entertainment!

  • I never had an APPLE ID with this email address and I have no idea why this is this showing to me?

    Every time I restore my iPhone from iCloud Backup, this apple id SHOWS UP  and asking password. But I never had an APPLE ID with this email address and I have no idea why this is this showing to me? Could anyone help me to remove it from my Applr ID as it seems somehow its linked to my iCloud Backup. Thank you.
    <Email Edited By Host>

    Hi Ralph,
    I have received the iPhone 5s from my carrier EE UK. I never had a second hand device as all my previous iPhones received from my carrier. Every time I restore from iCloud backup, first I enter my Apple ID and Password, then it authenticates and goes through next process and updates iCloud settings, right after initial settings then it displayes enter your password where the Apple ID is the metntioned Apple ID and in the bottom it says "Skip this to go next process" or something. I have to press that everytime to skip it, then restore my backup from iCloud and then when I'm in iPhone home it asks me for the password of that mentoned email. So everytime I change the email address to my Apple ID then enter my password that activates my iCloud services and start downloading all the apps I installed.
    Its really weird to be honest and I don't know how to remove that email address from that process and seems its there.
    N.B. When I had iPhone 4s, Apple Store did replace my iPhone 4s with a new one due to the faulty WiFi.

  • My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    I was having this problem while still using Mavericks -- it started after a Mavericks update last spring.  During the initial Yosemite beta runs over the summer, it seemed to be fixed, but after the official launch in October, I had all sorts of problems keeping connected.  Its gotten a little better, but still happens to at least one of my devices every day.  Weird that we still cannot figure out why the connection keeps dropping on some devices, but not others, and then the next day, one of the devices that didn't disconnect the previous day will disconnect, but the ones that did disconnect, stay connected.  It's just sloppy, poorly written software for technology that isn't working the way it should.  If you turn off Continuity and Handoff on all your devices, you will probably see that everything stays connected.  With those turned off on all devices, TC stayed connected to everything for over a month.  The day I turned Continuity back on, all the problems started again.  It had something to do with the bluetooth version being used, the wifi routine, and Apple's AirPlay technology not quite getting along with each other.

Maybe you are looking for

  • Unable to download from my jest phone to my computer?

    I have tried to download my pictures from my jest phone to my computer no avail, any ideas?

  • Creation of IDOC through abap program.

    hello all, I hav created idoc through abap program. I hav used FM 'Master_idoc _distrribute'.this program creates an idoc but giving status 30. can any one tell me how to get status 03. I hav already created port, Logical sys,partner no.,distribution

  • Living in switzerland... don't want Swiss iTunes store as "Home" store ...

    American living Switzerland ... not really interested in Swiss top ten or reviews in German ... I started with iTunes from the US then suddenly I was redirected to Switzerland .... since then haven't found a way to set the startup store back to US ..

  • Bug SQL Dev 1.5.4 Build MAIN-5940 Exporting count(*) query results

    when trying to export query results containing an analytic count the export dialog fails to open: When running the following query select count(*) over (partition by dummy order by rownum) xx   from dual;right clicking on the results grid and selecti

  • Using Javadoc with generics

    hi, I have not yet found a way to use javadoc on my sources which contain some generics. The tool fails (with errors) and will eventually abort. Is there a doclet or a modified javadoc tool that will work? error example: AbstractModel.java:7: '{' exp