0

我不知道这个布局有什么问题:

<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" />

但它以这个错误关闭:

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)

我在这里做错了什么?

        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);
4

4 回答 4

5

请清理您的项目,因为您可能已经为Spinner, builds 分配了一个 id,但后来您为without buildingR.java分配了相同的名称。EditTextR.java

由于 R.java 保持对所有控件的引用,所以第一次分配给 spinner 所以R.java考虑这个 id 是一个 spinner 但现在您将它分配给 EditText 并且 R.java 在您 clean 和 build 之前完全不知道。

道德:有时您必须R.java手动构建

于 2012-04-06T06:31:42.250 回答
4

看来你做了如下代码:

Spinner mSpinner = (EditText) findViewById (R.id.spinner);

相反,它应该正确地转换为:

Spinner mSpinner = (Spinner) findViewById (R.id.spinner);
于 2012-04-06T06:10:11.883 回答
0

如果您使用的是 eclipse,那么转到Project -> Clean希望可以解决问题。它确实为我解决了。

于 2014-11-01T11:06:23.787 回答
0

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.

于 2016-04-07T18:57:18.953 回答