i am trying to create a spinner in dialog box
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 is
<?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_gravit开发者_运维知识库y="center_horizontal"></Button>
</LinearLayout>
error log
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)
could some one please tell what mistake am i committing? have spent over 2-3 hours to fix this, but in vain! i have no idea where the checkbox is coming into picture
Just cleaned the project and re ran. Worked absolutely fine.
Perhaps R.id.addressSpinner has the same value as a checkbox elsewhere in your app (another Activity, perhaps)?
精彩评论