Android ListView setAdapter

时间:2011-10-04 18:03:52

标签: listview android-activity

我有一个活动,我正在递归调用并使用ArrayAdapter在其中填充ListView。它第一次运行,但是当我从ListView中单击任何项​​目以获取嵌套项时,它会崩溃,从而产生以下错误。

java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
at android.widget.AbsListView.obtainView(AbsListView.java:1448)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1273)
at android.widget.ListView.onMeasure(ListView.java:1184)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at android.view.View.measure(View.java:8171)
at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

生成此错误的代码是。

    List<String[]> Categories;

    categoryList.setAdapter(new ArrayAdapter<String>(this,
        R.layout.white_list_item, R.id.catName,
        getCategories(Categories)));

    private String[] getSubCategories(List<String[]> Cats) {
        String[] rv = new String[Cats.size()];

        for (int c = 1; c < Cats.size(); c++) {
            rv[c - 1] = Cats.get(c)[0];
        }

        return rv;
    }

我缺少什么?

0 个答案:

没有答案