I am getting a very weird error in a very simple activity. The code is below

String s[];
    ListView saved_lst;
    public ListDatabaseHandler getname;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_saved);
        getname=new ListDatabaseHandler(getApplicationContext());

            Toast.makeText(getApplicationContext(), Integer.toString(getname.getAllName().size()), 2000).show();
            int y=getname.getAllName().size();
            s=new String[y];
            for (int i=0;i<y/2;i++){
                s[i]=getname.getAllName().get(i);
            }


        saved_lst=(ListView) findViewById(R.id.savedlist);
        ArrayAdapter<String> saveadapter =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,s);
        saved_lst.setAdapter(saveadapter);
    }

getname.getAllName returns an ArrayList of the names of all the tables in the database. I have pinpointed the problem to the last statement saved_lst.setAdapter(saveadapter);

The log cat shows that there is an uncaught exception.

What could be the reason for this not running?

Logcat

07-30 17:22:00.480: W/dalvikvm(5458): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-30 17:22:00.550: E/AndroidRuntime(5458): FATAL EXCEPTION: main
07-30 17:22:00.550: E/AndroidRuntime(5458): java.lang.NullPointerException
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.AbsListView.obtainView(AbsListView.java:2143)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.ListView.onMeasure(ListView.java:1158)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:247)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.TableRow.onMeasure(TableRow.java:114)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
07-30 17:22:00.550: E/AndroidRuntime(5458):     at android.view.View.measure(View.java:15518)

XML File:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/savedlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

Related posts

Recent Viewed