Why doesn't this arraylist work?
<p>Hi the following below works</p>

<pre><code>package com.ahmad.actionBar;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class FragMent1 extends Fragment {

    private String arry[] = { "Tofeeq", "Ahmad", "Fragment", "Example",
            "Tofeeq", "Ahmad", "Fragment", "Example" };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        ListView listView = new ListView(getActivity());
        ArrayAdapter&lt;String&gt; array = new ArrayAdapter&lt;String&gt;(getActivity(),
                android.R.layout.simple_list_item_1);

        for (String str : arry)
            array.add(str);
        listView.setAdapter(array);
        return listView;
    }
}
</code></pre>

<p>But when I'm trying to populate my array with string objetcs it doesn't work </p>

<pre><code>package com.ahmad.actionBar;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class FragMent1 extends Fragment {

    private String bookNames[];

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        ListView listView = new ListView(getActivity());
        ArrayAdapter&lt;String&gt; array = new ArrayAdapter&lt;String&gt;(getActivity(),
                android.R.layout.simple_list_item_1);

        bookNames= bookNames();//This doesn't work
        for (String str : bookNames)//This doesn't work
            array.add(str);
        listView.setAdapter(array);
        return listView;
    }

    private String[] bookNames(){
        SimpleBookManager testBook = new SimpleBookManager();
        for(int i=0; i &lt; testBook.count(); i++){
        bookNames[i]= testBook.getBook(i).getTitle();
    }
        return bookNames;
    }
}
</code></pre>

<p>I get following errors NullpointeException?? </p>

<pre><code>11-14 23:36:54.531: E/AndroidRuntime(1949): FATAL EXCEPTION: main
11-14 23:36:54.531: E/AndroidRuntime(1949): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ahmad.actionBar/com.ahmad.actionBar.ActionBarMain}: java.lang.NullPointerException
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.os.Looper.loop(Looper.java:137)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at java.lang.reflect.Method.invokeNative(Native Method)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at java.lang.reflect.Method.invoke(Method.java:511)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at dalvik.system.NativeStart.main(Native Method)
11-14 23:36:54.531: E/AndroidRuntime(1949): Caused by: java.lang.NullPointerException
11-14 23:36:54.531: E/AndroidRuntime(1949):     at com.ahmad.actionBar.FragMent1.bookNames(FragMent1.java:39)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at com.ahmad.actionBar.FragMent1.onCreateView(FragMent1.java:29)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.BackStackRecord.run(BackStackRecord.java:635)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.Activity.performStart(Activity.java:5017)
11-14 23:36:54.531: E/AndroidRuntime(1949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
</code></pre>

<p>Here's my SimpleBookManager class and I populate it manually so it shold't be null.</p>

<pre><code>package com.ahmad.actionBar;

import java.util.ArrayList;

public class SimpleBookManager implements BookManager {
    private ArrayList&lt;Book&gt; allBooks = new ArrayList&lt;Book&gt;();

    public ArrayList&lt;Book&gt; getAllBooks(){
    return  allBooks;
    }

    public int count(){
        return getAllBooks().size();
    }


    public Book getBook(int index){

        return allBooks.get(index);
    }
    public Book createBook(){
        Book book = new Book();
        allBooks.add(book);
        return book;
    }
    public void removeBook(Book book){
        allBooks.remove(book);
        //Remove instance of book
    }
    public void moveBook (int from, int to){
        Book book1 = allBooks.get(from);
        Book book2 = allBooks.get(to);
        allBooks.add(to, book1);
        allBooks.add(from, book2);

    }
    public int getMinPrice(){
    ArrayList&lt;Integer&gt; allPrices = getAllPrices();
    int smallestElem=allPrices.get(0);
    for(int i=0; i &lt; allPrices.size(); i++){
         if (smallestElem &gt; allPrices.get(i)){
             smallestElem = allPrices.get(i);
         }
      }
        return smallestElem;


    }
    public int getMaxPrice(){
        ArrayList&lt;Integer&gt; allPrices = getAllPrices();
        int biggestElem=allPrices.get(0);
        for(int i=0; i &lt; allPrices.size(); i++){
             if (biggestElem &lt; allPrices.get(i)){
                 biggestElem = allPrices.get(i);
             }
          }
            return biggestElem; 
    }
    public float getMeanPrice(){
        ArrayList&lt;Integer&gt; allPrices = getAllPrices();
        int total=0;
        for(int i=0; i &lt; allPrices.size(); i++){
             total+=allPrices.get(i);
          }
            return total/allPrices.size();  

    }
    public int getTotalCost(){
        ArrayList&lt;Integer&gt; allPrices = getAllPrices();
        int total=0;
        for(int i=0; i &lt; allPrices.size(); i++){
             total+=allPrices.get(i);
          }
            return total;
    }
    public void saveChanges(){
        //What to do here
    }
    private ArrayList&lt;Integer&gt; getAllPrices(){
        int totalElements = allBooks.size();
        ArrayList&lt;Integer&gt; allBookPrices = new ArrayList&lt;Integer&gt;();
        //loop through it
        for(int i=0; i &lt; totalElements; i++){
          allBookPrices.add(allBooks.get(i).getPrice());
        }
        return allBookPrices;
    }

    public SimpleBookManager(){
        Book harryPotter1 = createBook();
        Book harryPotter2 = createBook();


        harryPotter1.setAuthor("JK Rowling");
        harryPotter1.setCourse("Harry Potter Kunskap");
        harryPotter1.setPrice(199);
        harryPotter1.setTitle("Harry Potter and the philosifer Stone");
        harryPotter1.setIsbn("9780590353403");

        harryPotter2.setAuthor("JK Rowling");
        harryPotter2.setCourse("Harry Potter Kunskap");
        harryPotter2.setPrice(299);
        harryPotter2.setTitle("Harry Potter and snake");
        harryPotter2.setIsbn("0439064872");
    }
}
</code></pre>

<p>Has probably something to do with List like this example <a href="http://stackoverflow.com/questions/5140535/populating-arrayadapter-type-string">here</a> but I can't figure out the exact syntax in my example so any help would be very much appriciated.</p>
