2013-04-20 56 views
0

我想让HoloEverywhere类AutoCompleteTextView与我的应用程序一起工作。造成这种情况的主要原因是我想要的河洛主题预3.0设备(特别是API等级8-10)在这里工作是我的主要活动代码:HoloEverywhere AutoCompleteTextView java.lang.ClassCastException

package com.example.testautocomp; 

import org.holoeverywhere.widget.AutoCompleteTextView; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 

public class MainActivity extends Activity { 

    private AutoCompleteTextView m_edit; 

    private static final String[] items = { "lorem", "ipsum", "dolor", "sit", 
     "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel", 
     "augue", "purus", "sitter", "sitting", "sither", "sithar" }; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    m_edit = (AutoCompleteTextView)findViewById(R.id.edit2); 

    m_edit.setAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_dropdown_item_1line, items)); 
    } 
} 

也是我activity_main.xml中代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<AutoCompleteTextView 
    android:id="@+id/edit2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:completionThreshold="1" 
    android:hint="Testing" /> 
</LinearLayout> 

当我运行我的应用程序,它进入调试器Eclipse和紧迫简历(或F8)继续线程后,我的应用程序崩溃/强制关闭,我得到了我的logcat以下错误:

04-19 17:52:56.342: W/dalvikvm(675): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
04-19 17:52:56.422: E/AndroidRuntime(675): FATAL EXCEPTION: main 
04-19 17:52:56.422: E/AndroidRuntime(675): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testautocomp/com.example.testautocomp.MainActivity}: java.lang.ClassCastException: android.widget.AutoCompleteTextView cannot be cast to org.holoeverywhere.widget.AutoCompleteTextView 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.os.Looper.loop(Looper.java:137) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-19 17:52:56.422: E/AndroidRuntime(675): at java.lang.reflect.Method.invokeNative(Native Method) 
04-19 17:52:56.422: E/AndroidRuntime(675): at java.lang.reflect.Method.invoke(Method.java:511) 
04-19 17:52:56.422: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-19 17:52:56.422: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-19 17:52:56.422: E/AndroidRuntime(675): at dalvik.system.NativeStart.main(Native Method) 
04-19 17:52:56.422: E/AndroidRuntime(675): Caused by: java.lang.ClassCastException: android.widget.AutoCompleteTextView cannot be cast to org.holoeverywhere.widget.AutoCompleteTextView 
04-19 17:52:56.422: E/AndroidRuntime(675): at com.example.testautocomp.MainActivity.onCreate(MainActivity.java:22) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.Activity.performCreate(Activity.java:4465) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
04-19 17:52:56.422: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
04-19 17:52:56.422: E/AndroidRuntime(675): ... 11 more 

我如何解决这个CastClassException?

回答

-1

非常相似,这question

通过改变我的main_activity.xml到固定它:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<org.holoeverywhere.widget.AutoCompleteTextView 
    android:id="@+id/edit2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:completionThreshold="1" 
    android:hint="Testing" /> 
</LinearLayout> 

主要部分是org.holoeverywhere.widget.AutoCompleteTextView

0

不,你的以上操作不正确。您应该更改org.holoeverywhere.app.Activity上的活动基类。

+0

这可能是另一个问题,我现在试图使用com.actionbarsherlock.app.SherlockActivity使用org.holoeverywhere.widget.AutoCompleteTextView。我将如何让这两个一起工作,而不必像我的答案中那样更改我的main_activity.xml? – nommer 2013-04-22 23:02:11