Getting Null Pointer Exception error
<p>I'm getting data form the XML file like this:-</p>

<pre><code>   &lt;posts&gt;
          &lt;page id="1"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ Tile no. 1 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/right.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;

          &lt;page id="2"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ Tile no. 2 ]]&gt;
                      &lt;/title&gt;
          &lt;/page&gt;

          &lt;page id="3"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ Tile no. 3 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/left.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;
  &lt;/posts&gt;
</code></pre>

<p>this is example of my XML in which i'm getting element  and , i'm getting 10 page in single url in which 10 are present but not 10  are preset. It may be 3 or 6 or 1.</p>

<p>In my code i'm using SAX parser to parse this XML file i'm getting my data and able to display on the list View but i'm able to display images with them.</p>

<p>For displaying images i'm using LazlyList Example (ImageLoader Class).</p>

<p>Here is my code below:-</p>

<p>MainActivity.java</p>

<pre><code>public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    static final String URL = "http://www.xyz.com/api.php?page_id=1";

    ItemList itemList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        XMLParser parser = new XMLParser();
        String XML = parser.getXmlFromUrl(URL);

        System.out.println("This XML is ========&gt;"+XML);

       try
       {
           SAXParserFactory spf = SAXParserFactory.newInstance();
           SAXParser sp = spf.newSAXParser();
           XMLReader xr = sp.getXMLReader();

           /** Create handler to handle XML Tags ( extends DefaultHandler ) */
           MyXMLHandler myXMLHandler = new MyXMLHandler();
           xr.setContentHandler(myXMLHandler);

           ByteArrayInputStream is = new ByteArrayInputStream(XML.getBytes());
           xr.parse(new InputSource(is));
      }
      catch(Exception e)
      {

      }

      itemList = MyXMLHandler.itemList;

      ArrayList&lt;String&gt; listItem= itemList.getTitle();
      ArrayList&lt;String&gt; listManu = itemList.getSmallimages();


      System.out.println("(ListItem)=======&gt;"+listItem);
      System.out.println("(ListManu)=======&gt;"+listManu);

    //  String ar[];
      Object obj[]=listManu.toArray();
      String[] stringArray=Arrays.asList(obj).toArray(new String[obj.length]);
      System.out.println("Array to String"+Arrays.toString(stringArray));
     // ar=(String[]) listManu.toArray();


     ListView lview = (ListView) findViewById(R.id.listview1);
     myAdapter adapter = new myAdapter(this, listItem, stringArray);
     lview.setAdapter(adapter);        

}
</code></pre>

<p>myAdapter.java</p>

<pre><code>public class myAdapter extends BaseAdapter 
{
    ArrayList&lt;String&gt; listTitle;
    String [] data;
    ImageLoader imageLoader;


    Activity activity;

    public myAdapter(Activity activity, ArrayList&lt;String&gt; listTitle, String[] d) {
        super();
        this.listTitle = listTitle;
        this.data = d;


        this.activity = activity;
        this.imageLoader = new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return data.length;

    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    private class ViewHolder
    {
        TextView txtViewTitle;
        ImageView image;


    }

    public View getView(int position, View view, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder title;
        LayoutInflater inflater = activity.getLayoutInflater();

        if(view==null)
        {
            view = inflater.inflate(R.layout.lview_row, null);
            title = new ViewHolder();

            title.txtViewTitle = (TextView) view.findViewById(R.id.txtItem);
            title.image = (ImageView) view.findViewById(R.id.list_image);

            view.setTag(title);
        }
        else
        {
            title = (ViewHolder) view.getTag();
        }

        title.txtViewTitle.setText(listTitle.get(position));


        imageLoader.DisplayImage(data[position], title.image);

        return view;
    }
}
</code></pre>

<p>\</p>

<p>when i'm using return data.length then i'm getting images and tile only no. of images are present  because String [] is storing images only not the spaces...</p>

<pre><code>public int getCount() {
            return data.length;
</code></pre>

<p>but when i changed data.length to listTitle.size()</p>

<pre><code>public int getCount() {
            return listTitle.size();
</code></pre>

<p>getting the Null Pointer Exception i'm using listTilte.size() because it give the full list...</p>

<p>Any one plz suggest me how can i able to solve this issue and getting images and full title data in the list view and where images is present where only i will getting image with title otherwise only title is display on the list view...</p>

<p>Thanks in Advanced.</p>
