android checkbox box issue

Posted by raqz on Stack Overflow See other posts from Stack Overflow or by raqz
Published on 2011-03-13T08:03:11Z Indexed on 2011/03/13 8:10 UTC
Read the original article Hit count: 463

Filed under:
|

i have this check box in a alertdialog. when i try to check the state of the checkbox, the application force closes. any idea why?

LayoutInflater factory = LayoutInflater.from(NewActivity.this);
        final View textDisplayView = factory.inflate(R.layout.nearestlocs, null);
        final AlertDialog.Builder newAlert = new AlertDialog.Builder(NewActivity.this);
        newAlert.setView(textDisplayView);

        final CheckBox checkBoxLab = (CheckBox) findViewById(R.id.checkboxlab);
newAlert.setPositiveButton("Display on Map",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                if(checkBoxLab.isChecked()){
                    libDisplayFlag = true;
                }

error log

 03-13 08:01:58.273: ERROR/AndroidRuntime(6188): Uncaught handler: thread main exiting due to uncaught exception
    03-13 08:01:58.292: ERROR/AndroidRuntime(6188): java.lang.NullPointerException
    03-13 08:01:58.292: ERROR/AndroidRuntime(6188):     at com.isproj3.NewActivity$3.onClick(NewActivity.java:158)
    03-13 08:01:58.292: ERROR/AndroidRuntime(6188):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
    03-13 08:01:58.292: ERROR/AndroidRuntime(6188):     at android.os.Handler.dispatchMessage(Handler.java:99)

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="horizontal"
        android:gravity="center" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1">
        <CheckBox android:id="@+id/checkboxlib" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Library"
            android:gravity="left" android:textColor="#FF0000"
            android:paddingBottom="5px" android:textSize="07pt" android:checked="true" />
        <TextView android:id="@+id/librarytext" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:gravity="center"
            android:paddingBottom="5px" android:textSize="8pt" />
    </LinearLayout>
</LinearLayout>

© Stack Overflow or respective owner

Related posts about android

Related posts about checkbox