我从命令行构建了我的 android 项目并使用ant debug install
. 但是在我将一个名为Android-PullToRefresh的外部项目导入到我的项目后,我的项目在运行时变得异常。有时,在我在 xml 布局文件中添加新 id 或删除 id 后,我的编译运行良好,但是当应用程序开始运行时,它会抛出一个ClassCastException
.
当它发生时,我只能用ant clean && ant debug install
它来修复它。但是重新编译一个洞项目需要双倍的时间,我不希望编译一个项目一分钟或更长时间。那么我可以做一些技巧来使这个错误不再发生吗?
堆栈跟踪:
E/AndroidRuntime(21226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhangdan.preferential/com.zhangdan.preferential.RecommendActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to com.handmark.pulltorefresh.library.PullToRefreshListView
E/AndroidRuntime(21226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
E/AndroidRuntime(21226): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
E/AndroidRuntime(21226): at android.app.ActivityThread.access$600(ActivityThread.java:142)
E/AndroidRuntime(21226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
E/AndroidRuntime(21226): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21226): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21226): at android.app.ActivityThread.main(ActivityThread.java:4931)
E/AndroidRuntime(21226): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21226): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime(21226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
E/AndroidRuntime(21226): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21226): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to com.handmark.pulltorefresh.library.PullToRefreshListView
E/AndroidRuntime(21226): at com.zhangdan.preferential.RecommendActivity.findViews(RecommendActivity.java:65)
E/AndroidRuntime(21226): at com.zhangdan.preferential.RecommendActivity.onCreate(RecommendActivity.java:58)
E/AndroidRuntime(21226): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime(21226): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(21226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
E/AndroidRuntime(21226): ... 11 more
W/ActivityManager( 380):
推荐Activity.java:
64 private void findViews() {
65 mFakeListView = (PullToRefreshListView)findViewById(R.id.refreshable_list);
66 mListView = mFakeListView.getRefreshableView();
67 }
xml:
1 <?xml version="1.0" encoding="utf-8"?>
2 <com.handmark.pulltorefresh.library.PullToRefreshListView
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:ptr="http://schemas.android.com/apk/res-auto"
5 android:id="@+id/refreshable_list"
6 android:layout_width="fill_parent"
7 android:layout_height="fill_parent"
8 android:cacheColorHint="#00000000"
9 android:fadingEdge="none"
10 android:listSelector="@android:color/transparent"
11 android:divider="@null"
12 android:paddingTop="5dip"
13 android:paddingBottom="5dip"
14 android:scrollbarStyle="outsideOverlay"
15 ptr:ptrMode="both" />