2013-04-20 77 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