使用listview和Arrayadapter时的Nullpointerexception

时间:2013-08-08 07:01:07

标签: nullpointerexception android-arrayadapter android-dialog

您好我正在尝试使用listview将日历事件填充到dailog中,同时将适配器设置为listview我将获得nullpointerexception。下面是我的代码

final Dialog dialog = new Dialog(getActivity());
                           dialog.setContentView(R.layout.list_view);
                            dialog.setTitle("Events");

                              ArrayAdapter<String> ad = new ArrayAdapter<String>(getActivity(),R.layout.list_view,R.id.text,desc);//desc your string array 
                              myList.setAdapter(ad);

下面是我的布局xml文件

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#FFFFFF" />

         <ListView
            android:id="@+id/mylist"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp" />
     </LinearLayout>    

不确定我在哪里做错了。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

尝试

dialog = new Dialog(your_activity.this);

同样在全球范围内宣布..