0

I am trying to get the HoloEverywhere class AutoCompleteTextView to work with my app. The main reason for this is I want the Holo theme to work on pre 3.0 devices (specifically API levels 8-10) Here is my main activity code:

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

also my activity_main.xml code:

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

When I run my app, it goes into the debugger for eclipse and after pressing resume (or F8) to continue the thread, my app crashes/force closes and I get the following error in my 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

How do i fix this CastClassException?

nommer
  • 2,730
  • 3
  • 29
  • 44

2 Answers2

0

No, your action above incorrect. You should change activity base class on org.holoeverywhere.app.Activity.

Prototik
  • 935
  • 4
  • 7
  • this might be for another question, I am now trying to use org.holoeverywhere.widget.AutoCompleteTextView using com.actionbarsherlock.app.SherlockActivity. How would I get these two to work together without having to change my main_activity.xml like in my answer? – nommer Apr 22 '13 at 23:02
-1

Very similar to this question

Fixed it by changing my main_activity.xml to:

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

the main part being org.holoeverywhere.widget.AutoCompleteTextView

Community
  • 1
  • 1
nommer
  • 2,730
  • 3
  • 29
  • 44