Reputation: 17119
I don't know what's the problem with this layout :
<ImageView
android:id="@+id/seticonimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:contentDescription="@string/description"
android:scaleType="fitStart"
android:src="@drawable/cm7_icon" />
<EditText
android:id="@+id/vsname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/seticonimage"
android:hint="@string/entername"
android:inputType="text" />
<EditText
android:id="@+id/vsdesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/vsname"
android:layout_toLeftOf="@+id/seticonimage"
android:hint="@string/shrtdesc"
android:inputType="text" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/vsdesc"
android:layout_toLeftOf="@+id/seticonimage"
android:prompt="@string/icon_prompt" />
<TextView
android:id="@+id/spinnerinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner"
android:layout_below="@+id/spinner"
android:layout_toLeftOf="@+id/seticonimage" />
But it closes with this error :
04-06 06:01:18.203: E/AndroidRuntime(1979): java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.EditText
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.manager.boot.free.MultiBootManager.onContextItemSelected(MultiBootManager.java:144)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.app.Activity.onMenuItemSelected(Activity.java:2509)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3521)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.widget.AbsListView$1.run(AbsListView.java:3168)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.os.Handler.handleCallback(Handler.java:605)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.os.Looper.loop(Looper.java:137)
04-06 06:01:18.203: E/AndroidRuntime(1979): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-06 06:01:18.203: E/AndroidRuntime(1979): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 06:01:18.203: E/AndroidRuntime(1979): at java.lang.reflect.Method.invoke(Method.java:511)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-06 06:01:18.203: E/AndroidRuntime(1979): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-06 06:01:18.203: E/AndroidRuntime(1979): at dalvik.system.NativeStart.main(Native Method)
What am I doing wrong here?
final View textEntryView = factory.inflate(R.layout.editvslayout,
null);
final EditText evsname = (EditText) textEntryView
.findViewById(R.id.vsname);
final EditText evsdesc = (EditText) textEntryView
.findViewById(R.id.vsdesc);
final Spinner spinner = (Spinner) textEntryView
.findViewById(R.id.spinner);
final ImageView i = (ImageView) textEntryView
.findViewById(R.id.seticonimage);
Upvotes: 0
Views: 5321
Reputation: 2577
Using Android Studio / IntelliJ 15 I often have to 'Build/Clean Project' a few times. When that doesn't work (which is fairly often), I end up deleting the Build directory. Then it works. I can't offer a reason why, but I'd love one from IntelliJ. In my case IntelliJ is mixing up the values for view IDs.
Upvotes: 0
Reputation: 450
If you are using eclipse then goto Project -> Clean hopefully that will resolve the issue. It did resolved for me.
Upvotes: 0
Reputation: 42016
Please clean your project because it may be possible that you had assign an id to Spinner
, R.java
builds, but later you assign the same name to EditText
without building R.java
.
As R.java keeps reference of all controls, so at first time you assign to spinner so R.java
consider that this id is a spinner but now you assigned it to EditText and R.java is totally unaware until you clean and build .
moral: sometimes you have to build R.java
manually
Upvotes: 5
Reputation: 128428
Its seems that you have did code like:
Spinner mSpinner = (EditText) findViewById (R.id.spinner);
Instead, it should be casted properly as:
Spinner mSpinner = (Spinner) findViewById (R.id.spinner);
Upvotes: 4