Results 1 to 2 of 2
  1. #1
    shahazzat is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default String array problem

    What is the problem of following code:

    public void st(){

    String[] a=null;
    String a1="Hello....";

    for(int i=0;i<5;i++){


    Exception in thread "main" java.lang.NullPointerException

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: String array problem

    Your variable named a is null, so you can't dereference it. Yet you try to dereference it by using the index[] operator on it. Take a look at the tutorials to see how to initialize an array.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Searching a string in object array? For loop problem?
    By java-newbie in forum New To Java
    Replies: 2
    Last Post: 11-20-2011, 09:26 PM
  2. Replies: 4
    Last Post: 07-27-2010, 08:52 PM
  3. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  4. Searching In a String Array - Problem
    By DillMan in forum New To Java
    Replies: 4
    Last Post: 12-07-2008, 09:12 PM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts