好吧,这似乎很愚蠢..但现在这让我发疯了。我有一个AutoCompleteTextView
看起来像:
<AutoCompleteTextView
android:id="@+id/etActionSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@+id/LinearLayout2"
android:drawableLeft="@android:drawable/ic_menu_search"
android:drawablePadding="7dp"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="start typing a name"
android:inputType="textFilter"
android:visibility="gone" />
它曾经是EditText
不久前的事,但后来我只是手动更改了 XML(成为一个AutoCompleteTextView
),而没有删除View
并再次创建它。我在代码中引用它:
private AutoCompleteTextView etActionSearch; //class field
etActionSearch = (AutoCompleteTextView) actionBar.getCustomView()
.findViewById(R.id.etActionSearch);
etActionSearch.setThreshold(1);
现在的问题是:在我用来测试应用程序的设备上,自从它创建以来一切正常。现在我将项目发送给我的一个伙伴,他在运行相同 Android 版本的设备上运行它:
java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.AutoCompleteTextView
我给他发了一个导出的.apk,同样的问题,崩溃了。我在我的设备上安装了SAME .apk,一切正常。我在模拟器上运行此代码(第一次在模拟器上运行) - 同样Exception
,崩溃。我删除R.java
了 gen 文件夹,多次清理项目,问题仍然存在......我只问:到底发生了什么?
已解决的建议:不要在晚上编码