I've been using a custom class ("AutoResizeTextView") that extends TextView
(see the accepted answer in this question). However, when trying to initialize this AutoResizeTextView, I get a classcastexception.
Here is some code:
Splash.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
...
// Line that causes error ------v
final AutoResizeTextView appName = (AutoResizeTextView) findViewById(R.id.title_text);
...
}
splash.xml:
<TextView
android:id="@+id/title_text"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/welcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="@string/app_name"
android:textColor="@android:color/white"
android:textSize="35dp" />
Logcat:
08-01 10:43:33.471: E/AndroidRuntime(6433): FATAL EXCEPTION: main
08-01 10:43:33.471: E/AndroidRuntime(6433): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.projects.package.name.Splash}: java.lang.ClassCastException: android.widget.TextView
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.os.Looper.loop(Looper.java:123)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 10:43:33.471: E/AndroidRuntime(6433): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 10:43:33.471: E/AndroidRuntime(6433): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 10:43:33.471: E/AndroidRuntime(6433): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-01 10:43:33.471: E/AndroidRuntime(6433): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-01 10:43:33.471: E/AndroidRuntime(6433): at dalvik.system.NativeStart.main(Native Method)
08-01 10:43:33.471: E/AndroidRuntime(6433): Caused by: java.lang.ClassCastException: android.widget.TextView
08-01 10:43:33.471: E/AndroidRuntime(6433): at my.projects.package.name.Splash.onCreate(Splash.java:44)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 10:43:33.471: E/AndroidRuntime(6433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
I assumed that since this custom class extends TextView
, and since R.id.title_text
is a TextView
, this would work. Any ideas what's going wrong?
Some things I've tried:
- Project -> Clean
- Restart Eclipse
- Ensure every file exists where the code is attempting to find it at