类强制转换异常对话框android

时间:2011-03-14 01:15:04

标签: android android-layout alertdialog

我正在尝试在对话框中创建一个微调器

final Dialog viewDialog = new Dialog(NewActivity.this);
        viewDialog.getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        viewDialog.setTitle("Nearest "+currentLocationType);
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View dialogView = li.inflate(R.layout.nearestlocs, null);
            viewDialog.setContentView(dialogView);
// error is in the next line
            Spinner addressSpinner = (Spinner) 
dialogView.findViewById(R.id.addressSpinner); 
        Button okButton = (Button) dialogView.findViewById(R.id.okbutton);

nearestlocs.xml是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Spinner android:id="@+id/addressSpinner"
        android:drawSelectorOnTop="true" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button android:text="Show route on Map" android:id="@+id/okbutton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"></Button>

</LinearLayout>

错误日志

 03-14 01:09:24.686: WARN/dalvikvm(6583): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-14 01:09:24.686: ERROR/AndroidRuntime(6583): Uncaught handler: thread main exiting due to uncaught exception
03-14 01:09:24.706: ERROR/AndroidRuntime(6583): java.lang.ClassCastException: android.widget.CheckBox
03-14 01:09:24.706: ERROR/AndroidRuntime(6583):     at com.isproj3.NewActivity.displayNearestLocations(NewActivity.java:177)
03-14 01:09:24.706: ERROR/AndroidRuntime(6583):     at com.isproj3.NewActivity.access$3(NewActivity.java:160)
请问有人能告诉我犯了什么错误吗?花了2-3个多小时来解决这个问题,但徒劳无功!我不知道复选框在哪里进入图片

2 个答案:

答案 0 :(得分:5)

刚清理完项目并重新开始。工作得非常好。

答案 1 :(得分:1)

也许R.id.addressSpinner与应用程序中其他位置的复选框具有相同的值(可能是另一个Activity)?